我有以下清除输入表格的功能:
function clearForm(form) {
$(':input', form).each(function() {
var type = this.type;
var tag = this.tagName.toLowerCase();
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;
});
};
有什么方法可以阻止它清除“隐藏”的输入?
提前致谢。
答案 0 :(得分:3)
当然,而不是
$(':input', form)
使用
$(':input:visible', form)
答案 1 :(得分:0)
$(':input:visible', form).each(...
答案 2 :(得分:0)
$(':input:visible').val([])
你不需要每个函数中的任何代码,上面的单行就可以了。