Last active
August 29, 2015 14:08
-
-
Save z007/d4e4443c4d17e5a9db2c to your computer and use it in GitHub Desktop.
图片大小上传限制 visibility 属性规定元素是否可见。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>图片大小上传限制</title> | |
</head> | |
<script type="text/javascript"> | |
function Judge(){ | |
//判断图片的大小是否大于50,或者小于0(没有选择图片) | |
if (document.all.myImg.fileSize > 1024 * 50 || document.all.myImg.fileSize <= 0) { | |
alert('请选择小于50K的图片!'); | |
return false; //不执行任何操作 | |
} | |
else { | |
alert('上传没问题'); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<input type="file" id="jia" onchange="document.all.myImg.src=this.value"/> | |
<!--服务器获取上传图片 从这个未显示的imgs上--><!--visibility 属性规定元素是否可见。 | |
提示:即使不可见的元素也会占据页面上的空间。请使用 "display" 属性来创建不占据页面空间的不可见元素。 | |
说明 <img src="" style="visibility:hidden"> | |
--> | |
<img src="" id="myImg" style="display:none" alt="图片"> | |
<button onclick="Judge()"/> 上传图片 | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment