日期:2014-05-16  浏览次数:20333 次

<input type="file">我要怎么实现在这个input获得光标的时候,把里面的value清空?
查了资料,好像 <input   type= "file "> 的value是只读的?不能写
document.getElementById( 'id ').value= ' ';

谁能告诉我一下?

------解决方案--------------------
这样可以实现功能,问题是选择文件后需先让焦点离开控件

<script>
var i=0;
var f = document.getElementById( 'file ');
function fn1()
{
if(f.value!= ' ' && i==1)
{
f.outerHTML= " <input type=\ 'file\ ' id=\ 'file\ ' onfocus=\ 'fn1()\ ' onblur=\ 'fn2()\ '> ";
i=0;
}
}
function fn2(){if(f.value!= ' ')i=1;}
</script>

------------------------------
<input type= "file " id= "file " onfocus= "fn1() " onblur= "fn2() " />