close
<input type="file" name="FileUpload1" id="FileUpload1" class="form-control" style="width:400px;" runat="server" /> <img id="testImg" src="#" alt="your image" /> <script> $(function () { $('#testImg').hide(); }); function getImgSize(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $('#testImg').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); } } $('#testImg').on('load', function () { if (($(this).width() == 77) && ($(this).height() == 50)) { } else { $('#<%=FileUpload1.ClientID%>').val(''); alert('※上傳檔案尺寸不符規定※'); } }) $('#<%=FileUpload1.ClientID%>').change(function () { getImgSize(this); }); </script>
全站熱搜