- JScript code
<html> <body> <input type="file" name="uploadfile" id="uploadfile" [color=#ff0000]onChange="value();[/color]"/> <script> document.getElementById('uploadfile').[color=#ff0000]onchange [/color]= function () { alert('Selected file: ' + this.value); }; function value(){ alert(document.getElementById('uploadfile').value); document.getElementById('uploadfile').value=''; } </script> </body> </html> 看看这段代码 ,两个onchange,为什么只执行了<script>标签里的那个,<input>标签里的那个怎么不行?
------解决方案--------------------
<html>
<body>
<input type="file" name="uploadfile" id="uploadfile" onChange="value();"/>
<script>
document.getElementById('uploadfile').onchange = function () {
alert('Selected file: ' + this.value);
value()
};
function value(){
alert(document.getElementById('uploadfile').value);
document.getElementById('uploadfile').value='';
}
</script>
</body>
</html>
你下面的代码覆盖了onChange="value()"的代码
你放在一起应该可以了
------解决方案--------------------
value是表单元素的属性名,不能用作自定义函数的函数名。换个函数名就可以了。