Ibr*_*mar 2 forms jquery reset
可能重复:
使用jQuery清空表单
我正在使用jQuery函数来清除我的所有表单值.
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = '';
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
Run Code Online (Sandbox Code Playgroud)
上述功能的问题是它不会重置文件输入字段.无论如何,我可以扩展该功能,并使其与清除文件输入字段一起使用.
这是我正在使用的文件输入字段HTML代码.
<section><label for="productimg">Picture<br></label>
<div><input type="file" id="productimg" name="productimg"></div>
</section>
Run Code Online (Sandbox Code Playgroud)
谢谢..
Jay*_*dra 12
尝试使用表单重置,以返回初始值 -
$('#form_id').each(function(){
this.reset();
});
Run Code Online (Sandbox Code Playgroud)
演示- http://jsfiddle.net/hPytd/&http://jsfiddle.net/hPytd/1/
归档时间: |
|
查看次数: |
24769 次 |
最近记录: |