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

如何使用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创建一个这样的标签