用JS限制图片的尺寸 限制图片的显示尺寸图片上传的大小 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 判断上传图片大小:-------------------------<input id=inp type="file"> <button onclick="ys()">Test</button> <script> var img=null; function ys() { if(img)img.removeNode(true); img=document.createElement("img"); img.style.position="absolute"; img.style.visibility="hidden"; img.attachEvent("onreadystatechange",orsc); img.attachEvent("onerror",oe); document.body.insertAdjacentElement("beforeend",img); img.src=inp.value; } function oe() { alert("cant load img"); } function orsc() { if(img.readyState!="complete")return false; alert("图片大小:"+img.offsetWidth+"X"+img.offsetHeight); alert("图片尺寸:"+img.fileSize); } </script>-----------------------------不过这代码的缺点是还使用插件,所以如果把他防在web里面,是不好用的。文件大小一般还是在服务器端来检测的.*****************************下面的程序是控制图片显示大小,可以把图片等比例缩放:-----------------------------<script type="text/javascript">// 让图片成比例缩小function changeImage(ImgD){ var image=new Image(); image.src=ImgD.src; if(image.width>185){ ImgD.width=185; ImgD.height=(185*image.height)/image.width; image.width=ImgD.width; image.height=ImgD.height; } if(image.height>169){ ImgD.height=169; ImgD.width=(169*image.width)/image.height; image.height = ImgD.height; image.width = ImgD.width; } ImgD.alt = image.width + "×" + image.height;}</script><img src="" width="10" height="70" onload="changeImage(this)"/>------------------------------这个程序需要主义的是,在加载大图片的时候,要给图片加载留够充足的时间否则,会出现错误的. ajax的返回值问题 iframe父子窗口间JavaScript方法调用 渐显效果 求助 [请教]Javascript代码管理 如何把在javascrip中定义的值用POST传给下一页面 如何用JavaScript获取客户端 硬件信息 高手快来帮我! 请问如何限制只输入中文字符? 关于数学运算函数使用格式的问题 如何将select中选中的项返回到一个数组中? 网页右边跟随滚动条上下移动的小广告 框架提交传值的问题????
-------------------------
<input id=inp type="file">
<button onclick="ys()">Test</button>
<script>
var img=null;
function ys()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=inp.value;
}
function oe()
{
alert("cant load img");
}
function orsc()
{
if(img.readyState!="complete")return false;
alert("图片大小:"+img.offsetWidth+"X"+img.offsetHeight);
alert("图片尺寸:"+img.fileSize);
}
</script>
-----------------------------
不过这代码的缺点是还使用插件,所以如果把他防在web里面,是不好用的。文件大小一般还是在服务器端来检测的.
*****************************
下面的程序是控制图片显示大小,可以把图片等比例缩放:
-----------------------------
<script type="text/javascript">
// 让图片成比例缩小function changeImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>185){
ImgD.width=185;
ImgD.height=(185*image.height)/image.width;
image.width=ImgD.width;
image.height=ImgD.height;
}
if(image.height>169){
ImgD.height=169;
ImgD.width=(169*image.width)/image.height;
image.height = ImgD.height;
image.width = ImgD.width;
}
ImgD.alt = image.width + "×" + image.height;
}
</script>
<img src="" width="10" height="70" onload="changeImage(this)"/>
------------------------------
这个程序需要主义的是,在加载大图片的时候,要给图片加载留够充足的时间否则,会出现错误的.