联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

jquery清空表单数据示例分享 - Web前端

作者:98wpeu发布时间:2026-06-13分类:网页前端技术浏览:4


导读:复制代码代码如下:functionclearFORM(form){ //iterateoveralloftheinputsfortheForm //e...

复制代码 代码如下:
function clearFORM(form) {
  // iterate over all of the inputs for the Form
  // element that was passed in
  $(':input', form).each(function() {
    vartype = this.type;
    var tag = this.tagName.toLowerCase(); // normalize case
    // it's ok to reset the valueattr 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;
  });
};

标签:表单示例清空数据Webjquery


网页前端技术排行
最近发表
网站分类
标签列表