我想清除表单中的所有输入和文本区域字段。当使用reset类的输入按钮时,它的工作原理如下:

$(".reset").bind("click", function() {
  $("input[type=text], textarea").val("");
});

这将清除页面上的所有字段,而不仅仅是表单中的字段。我的选择器看起来像什么形式的实际重置按钮生活?


当前回答

我用这个:

$(".reset").click(function() {
  $('input[type=text]').each(function(){
     $(this).val('');
  });
});

这是我的按钮:

<a href="#" class="reset">
  <i class="fa fa-close"></i>
     Reset
</a>

其他回答

为什么不使用document.getElementById("myId").reset();? 这是简单而漂亮的

$('#editPOIForm').each(function(){ 
    this.reset();
});

其中editPOIForm是表单的id属性。

如果我想清除除accountType以外的所有字段,请使用以下方法

$q(':input','#myform').not('#accountType').val('').removeAttr('checked').removeAttr('selected');

这不会处理表单输入字段默认值为非空的情况。

应该可以工作

$('yourdiv').find('form')[0].reset();

简单却很有魅力。

$("#form").trigger('reset'); //jquery
document.getElementById("myform").reset(); //native JS