如何使用jquery 清空 input type="file" 的内容

SambaGao 2011-04-06 05:59:02
<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.

请大家帮帮忙。在此谢过。
...全文
3650 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
北方的猿 2012-05-29
  • 打赏
  • 举报
回复
楼上的代码貌似不能用啊!
打字员 2011-04-07
  • 打赏
  • 举报
回复

<!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>
xuxubaby 2011-04-07
  • 打赏
  • 举报
回复
移除掉,再用jquery创建一个这样的标签
SambaGao 2011-04-07
  • 打赏
  • 举报
回复
var file = jQuery('.fileInput');
file.after(file.clone().val(''));
file.remove();

I have been solved.

thanks.buddy.
SambaGao 2011-04-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 kk3k2005 的回复:]

引用 2 楼 nihaozhangchao 的回复:

引用 1 楼 cuixiping 的回复:

那就移除,再添加



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

thanks.

是让你在前台 移除 添加
[/Quote]
如果移除的话,怎么和后台再连上呢?就算连上了哪么它的值不就又出来了吗?
请大家说的再具体些。谢了。
KK3K2005 2011-04-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 nihaozhangchao 的回复:]

引用 1 楼 cuixiping 的回复:

那就移除,再添加



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

thanks.
[/Quote]
是让你在前台 移除 添加
SambaGao 2011-04-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cuixiping 的回复:]

那就移除,再添加
[/Quote]


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

thanks.
cuixiping 2011-04-06
  • 打赏
  • 举报
回复
那就移除,再添加

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧