当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jquery清空表单数据示例代码分享

jquery清空表单数据示例代码分享

2019年03月21日  | 移动技术网IT编程  | 我要评论

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网