如何使用以下方法排除只读字段:在jquery中输入?

mel*_*aos 4 forms jquery readonly clear

到目前为止,我只使用了一些基本的jquery选择器和函数.但我正在看这个清晰的表单功能,我无法弄清楚如何添加它,所以我可以删除隐藏的输入和readonly输入清除.

任何人都可以帮忙吗?谢谢.

function clearForm(form) {
  // iterate over all of the inputs for the form
  // element that was passed in
  $(':input', form).each(function() {
 var type = this.type;
 var tag = this.tagName.toLowerCase(); // normalize case
 // it's ok to reset the value attr of text inputs,
 // password inputs, and textareas
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = "";
 // checkboxes and radios need to have their checked state cleared
 // but should *not* have their 'value' changed
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 // select elements need to have their 'selectedIndex' property set to -1
 // (this works for both single and multiple select elements)
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};
Run Code Online (Sandbox Code Playgroud)

Gum*_*mbo 13

如果元素readonly的声明中有属性,则可以使用jQuery的:not()选择器:

$(':input:not([readonly])', form)
Run Code Online (Sandbox Code Playgroud)

否则使用以下内容过滤只读元素:

$(':input', form).each(function() {
    if (this.readOnly) return;
    // …
});
Run Code Online (Sandbox Code Playgroud)