jquery 和 javascript 清空下传控件 方法总结
2014-05-27 10:06
691 查看
jquery 和 javascript 清空上传控件 方法总结
大家都知道清空上传控件“ <input type="file" />”用平常的value=“”无法实现清空
在这里给大家分享两种方法
//clone
function clearFileInputByClone(fileId) {
var cloneFile = $("#"+fileId).clone();
$("#"+fileId).replaceWith(cloneFile);
}
//html
function clearFileInputByHtml(fileId) {
var tempHTML = $("#"+fileId).parent().html();
$("#"+fileId).parent().html(tempHTML)
}
//outerHMTL
function clearFileInputByOuterHTML(fileId) {
var fileobj = document.getElementById(fileId);
fileobj.outerHTML = fileobj.outerHTML;
}
//各位如有更好的方法 多多交流
//测试
<form action="" id="form1">
<table>
<tr>
<td>名称:</td>
<td><input name="username" value="" /></td>
</tr>
<tr>
<td>附件:</td>
<td>
<input type="file" id="file_rest" />
<a href="javascript:clearFileInputByOuterHTML('file_rest')">清空</a>
<…………………………………………………………………………
详细页面:http://www.verydemo.com/demo_c110_i10825.html
大家都知道清空上传控件“ <input type="file" />”用平常的value=“”无法实现清空
在这里给大家分享两种方法
//clone
function clearFileInputByClone(fileId) {
var cloneFile = $("#"+fileId).clone();
$("#"+fileId).replaceWith(cloneFile);
}
//html
function clearFileInputByHtml(fileId) {
var tempHTML = $("#"+fileId).parent().html();
$("#"+fileId).parent().html(tempHTML)
}
//outerHMTL
function clearFileInputByOuterHTML(fileId) {
var fileobj = document.getElementById(fileId);
fileobj.outerHTML = fileobj.outerHTML;
}
//各位如有更好的方法 多多交流
//测试
<form action="" id="form1">
<table>
<tr>
<td>名称:</td>
<td><input name="username" value="" /></td>
</tr>
<tr>
<td>附件:</td>
<td>
<input type="file" id="file_rest" />
<a href="javascript:clearFileInputByOuterHTML('file_rest')">清空</a>
<…………………………………………………………………………
详细页面:http://www.verydemo.com/demo_c110_i10825.html
相关文章推荐
- jquery 和 javascript 清空上传控件 方法总结
- Javascript、jQuery 操作select控件大全(新增、修改、删除、选中、清空、判断存在等)
- Jquery获得控件值的三种方法总结
- 如何解决asp.net 在vs2010(.net framework 4.0)中listview控件用jquery,javascript为模版中的服务端控件注入事件的方法?因为vs2010在这个方面有存在的bug!
- Jquery获得控件值的三种方法总结
- JavaScript中清空数组的方法总结
- javascript使控件无效或者隐藏的方法总结
- Javascript访问html页面的控件的方法总结
- Jquery获得控件值的三种方法总结
- 【JavaScript】运用jQuery实现控件左右移动的三种方法
- Javascript、jQuery 操作select控件大全(新增、修改、删除、选中、清空、判断存在等)
- JavaScript、jQuery的遍历方法(each、forEach)总结
- javascript控制页面控件隐藏显示的两种方法
- 清空上传控件HtmlInputFile的方法
- javascript引用对象的方法 (总结)
- 关于Javascript与表单结合时出现"对象不支持此属性或方法"的问题总结(不断更新中...)
- 清空上传控件HtmlInputFile的方法
- [总结]获得控件的方法
- javascript控制页面控件隐藏显示的两种方法
- 用JavaScript隐藏控件的方法