<SCRIPT language=javascript>
function index_image_valid(){
document.pho_up.indeximg.src=document.pho_up.pho_index.value;
imagewidth=document.pho_up.indeximg.width;
imageheigth=document.pho_up.indeximg.height;
alert ("宽:"+imagewidth+"\n高:"+imageheigth);
}
</script>
</head>
<form name="pho_up" method="post" enctype="multipart/form-data">
<input type="file" name="pho_index" size="20" class=input Onchange="javascript:index_image_valid();">
<img name=indeximg>
</form>
function index_image_valid(){
document.pho_up.indeximg.src=document.pho_up.pho_index.value;
imagewidth=document.pho_up.indeximg.width;
imageheigth=document.pho_up.indeximg.height;
alert ("宽:"+imagewidth+"\n高:"+imageheigth);
}
</script>
</head>
<form name="pho_up" method="post" enctype="multipart/form-data">
<input type="file" name="pho_index" size="20" class=input Onchange="javascript:index_image_valid();">
<img name=indeximg>
</form>
解决方案 »
- 为什么样式总是不对呢?
- 有没有办法能吧 一个图片的SRC强行附加给另一个图片的SRC
- AJAX小聊天室火狐不兼容
- DIV没有设置ID属性,如何读取DIV中的innerHTML
- 浏览器的快捷键Ctrl+N是“新建窗口”,如何屏蔽
- 多个同名CHECKBOX,当没选中的时候该一行的输入框都不可用,另外还需要按照用户点击的顺序给它赋值,第一个选中的为1,第二个选中的为2,
- 一个关于iframe的问题,高手请进
- phpBB论坛
- zilong28:页面中使用SETITMEOUT设计了一个计时秒表,当页面中有alert弹出时,计时却停止了,如何使其继续计时
- jquery选择器,如何选中这个3D轮播图中完全不透明的元素
- 关于流媒体
- 怎样在ie中显示两个日期相减的天数?
我做了修改。
<SCRIPT language=javascript>
function index_image_valid(){
var img=new Image();
img.src=document.pho_up.pho_index.value;
imagewidth=img.width;
imageheigth=img.height;
fsize=img.fileSize/1024;
fsize=fsize.toFixed(1);
document.pho_up.cmd.disabled=true;
if(img.readyState!="complete")
window.setTimeout("index_image_valid()",10);
else
{alert ("宽:"+imagewidth+"\n高:"+imageheigth+"\n大小:"+fsize+" KB");
document.pho_up.cmd.disabled=false}
}
</script>
</head>
<form name="pho_up" method="post" enctype="multipart/form-data">
<input type="file" name="pho_index" size="20">
<input type=button name="cmd" value="测试图片大小" onclick="index_image_valid();">
</form>
Response.Write Request("a")
%>
<form method=post onsubmit="a.value=document.all.x.width + ':' + document.all.x.height">
<input name=a type=hidden>
<input type=file name=f onpropertychange='document.all.x.src=f.value'>
<input type=submit>
<img id=x style="visibility:hidden">
</form>
然后通过属性width和height来读取就可以了.如果有问题.看一下你的img是否放在不同的容器中.比如在body,form,iframe这样的东西里.如果有.可以再加上相应的标识.
这个判断还应该在img的onreadystatechange事件中处理,否则不能总是得到正确的信息