当前位置: 代码迷 >> JavaScript >> <input type="file">小弟我要如何实现在这个input获得光标的时候,把里面的value清空
  详细解决方案

<input type="file">小弟我要如何实现在这个input获得光标的时候,把里面的value清空

热度:428   发布时间:2012-02-07 17:45:37.0
<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() " />
  相关解决方案