renxiaoren

有时候可能需要实现这样的效果:注册表单或者地址表单等填写多个记录之后,想要清除重新填写,如果一个个删除非常麻烦,因此这时清除按钮非常必须。接下来为您详细介绍两个自己经历的便捷方法,需要了解的朋友参考下:

方法一:

function clearForm(){

  $(\':input\', form).each(function(){

    var type=this.type;

    var tagName=this.tagName.toLowerCase();

    if(type==\'text\'||type==\'password\'||type==\'textarea\'){

      $(this).val("");

    }else if(type==\'radio\'||type==\'checkbox\'){

       this.checked = false;

      或者:$(this).prop(false);

    }else if(tag==\'select\'){

       this.selectedIndex = -1;

    }

     });

}

 

方法二:

//在form表单中添加一个隐藏的reset按钮, 
<input type="reset" style="display:none;" /> 
//然后通过trigger来触发reset按钮 
function subform(){ 
/* ... 
*提交表单的代码部分 
* ... */ 
$("input[type=reset]").trigger("click");//触发reset按钮 } 

分类:

技术点:

相关文章:

  • 2022-02-04
  • 2021-11-28
  • 2021-11-28
  • 2021-12-09
  • 2022-01-07
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2021-11-30
  • 2022-01-07
  • 2021-11-27
  • 2021-11-28
  • 2021-11-19
  • 2021-12-30
  • 2021-12-06
相关资源
相似解决方案