首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2012-02-07 
input typefile我要怎么实现在这个input获得光标的时候,把里面的value清空?查了资料,好像 inputtype

<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() " />

热点排行