onchange在IE|firefox失效 本帖最后由 flymyhelp 于 2010-06-25 18:43:06 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript">function files(){ alert("test"); var file=document.getElementById("file").value; str=file.substring(file.lastIndexOf("."),file.length); if(/^[^jpg|gif|jpeg|png|bmp]$/.test(str.toLowerCase())) { alert("系统不支持此图片格式"); } else { document.getElementById("div1").innerHTML="<img src='"+file.value+"' style='border:6px double #ccc';padding:'5px';>"; }}</script></head><body><form method="post" enctype="multipart/form-data" action=""><input type="file" id="file" size="30" onchange="files();"/><div id="div1"></div></form></body></html> 不是失效,而是压根FILE就没有这个属性。按说提示已经说得很清楚了。碰到这类问题,就查下DOM对象所支持的属性和事件。 晕了。刚刚看了没关的另一个国外的帖,说是把javascript去掉就是了。试验了一下,还真是。但我刚才用JS查了FILE的事件列表,的确没有onchange。 1.直接onchange="funname()"2.不要使用file这个名字,input的id是file,方法名字也是file,在ie中都是全局变量,到底取哪个呢?3.正则有问题/^[^jpg|gif|jpeg|png|bmp]$/===》if(!/\.(?:jpg|gif|jpeg|png|bmp)$/i.test(....)) 为什么把JavaScript去掉就可以运行?这是什么原因呢,既然DOM都没有这样的属性与方法,为何还能运行? <input type="file" id="file1" size="30" onchange="javascript:files();"/></div></body><script>alert(document.getElementById("file1").onchange)</script>看看解释成什么样了?ie去掉了,应该可以加,出错应该是4楼的第2点,给换个id应该就能在ie中运行 帮忙分析一小段jquery json代码 如何用js获取系统字体 判断多项同name表单值是否重复? document.body.clientWidth显示问题 SINA的“与同时访问此页面的网友聊天”程序是怎么做得?有没相似的程序,谢谢 如何分解字符串? div在浏览器中的定位 分辨率和ie版本的问题?????在线等,立结分 请问怎样获得用户输入的Address 怎样在javascrip的函数里不打开另外的窗口,而执行一个php或asp程序。 根据网页的名字显示不同的图片要怎么写? 求一个价格的正则表达式!!!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function files()
{
alert("test");
var file=document.getElementById("file").value;
str=file.substring(file.lastIndexOf("."),file.length);
if(/^[^jpg|gif|jpeg|png|bmp]$/.test(str.toLowerCase()))
{
alert("系统不支持此图片格式");
}
else
{
document.getElementById("div1").innerHTML="<img src='"+file.value+"' style='border:6px double #ccc';padding:'5px';>";
}
}
</script>
</head><body>
<form method="post" enctype="multipart/form-data" action="">
<input type="file" id="file" size="30" onchange="files();"/>
<div id="div1">
</div>
</form></body>
</html>
按说提示已经说得很清楚了。碰到这类问题,就查下DOM对象所支持的属性和事件。
但我刚才用JS查了FILE的事件列表,的确没有onchange。
3.正则有问题/^[^jpg|gif|jpeg|png|bmp]$/===》if(!/\.(?:jpg|gif|jpeg|png|bmp)$/i.test(....))
<input type="file" id="file1" size="30" onchange="javascript:files();"/>
</div>
</body>
<script>
alert(document.getElementById("file1").onchange)
</script>
看看解释成什么样了?
ie去掉了,应该可以加,出错应该是4楼的第2点,给换个id应该就能在ie中运行