jquery清空表单数据示例分享

这篇文章主要介绍了jquery清空表单数据的示例,需要的朋友可以参考下

复制代码 代码如下:


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;
  });
};

您可能感兴趣的文章:

相关文章

最新评论

站长推荐

正版 Windows 10

正版Windows 10 家庭/专业版,操作系统限时抢购[¥1088→¥248]

站长推荐

正版 Office 软件

Microsoft Office 2016/2019/365 正版最低价仅需[ ¥148元]

大家感兴趣的内容

最近更新的内容

常用在线小工具

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdyxwf.html