上傳圖片js判斷圖片尺寸和格式兼容IE


<a target=_blank href="http://www.jb51.net/article/54587.htm">點擊打開鏈接</a>

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>js</title><script src="jscss/jquery.min.js"></script><style type="text/css">.preview_size_fake { /* 該對象只用來在IE下獲得圖片的原始尺寸,無其它用途 */filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);height: 1px;visibility: hidden;overflow: hidden;display: none;}</style></head><body><script type="text/javascript">$(function(){$(".head").change(function() {var val = $(this).val();if (!val.match(/.jpg|.gif|.png|.bmp/i)) {imgtype = false;alert('圖片格式無效!');} else {if (window.FileReader) {var reader = new FileReader(), file = this.files[0];reader.onload = function(e) {var image = new Image();image.src = e.target.result;image.onload = function() {alert(image.fileSize);if (image.width > 128 || image.height > 128) {fill = false;alert("頭像尺寸應在128x128之間");}}};reader.readAsDataURL(file);} else {//這是ie9版本$(".preview_size_fake").show();var objPreviewSizeFake = $(".preview_size_fake").get(0);var fileupload = $(this).get(0);fileupload.select();fileupload.blur();path = document.selection.createRange().text;if (/"\w\W"/.test(path)) {path = path.slice(1, -1);}objPreviewSizeFake.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = path;alert(objPreviewSizeFake.offsetWidth);if (objPreviewSizeFake.offsetWidth > 128 || objPreviewSizeFake.offsetHeight > 128) {fill = false;alert("頭像尺寸應在128x128之間");}document.selection.empty();}}});});</script><input class="head" type="file" name="avatar"><img class="preview_size_fake" /></body></html>


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com 联系我们: