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

怎么使用jquery 清空 input type="file" 的内容

2012-05-31 
如何使用jquery 清空 input typefile 的内容input accept accessKey alt classfileInput

如何使用jquery 清空 input type="file" 的内容
<input accept="" accessKey="" alt="" class="fileInput" dir="" lang="" name="j_id0:j_id10:fileName:inputFile:file" onblur="" onchange="" onclick="" ondblclick="" onfocus="" onkeydown="" onkeypress="" onkeyup="" onmousedown="" onmousemove="" onmouseout="" onmouseover="" size="" style="" tabindex="" title="" type="file" />


setInterval('ShowClearBtn()', 300);
   
  });
  function ShowClearBtn () {
  if (jQuery('.fileInput').val() != ''){
  jQuery('.clearBtn').css('visibility', 'visible');
  }
  }

在firefox and safari and 谷歌都没有问题。可以IE 就不行。我用的是IE 7.

请大家帮帮忙。在此谢过。

[解决办法]
那就移除,再添加
[解决办法]

探讨

引用:

那就移除,再添加



I think so。不过由于生成的file 在服务器端。所以再添加会很麻烦。

thanks.

[解决办法]
JScript code
<!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></head><body><input type="file" id="files" /><input type="button" id="btn" value="clear" /><script type="text/javascript">    document.getElementById('btn').onclick = function() {        var o = document.getElementById('files')        if(!!document.all) {            o.select();            document.execCommand("delete");        } else {            o.value = '';        }    }</script></body></html>
[解决办法]
移除掉,再用jquery创建一个这样的标签

热点排行