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

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

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


当前回答

@using (Ajax.BeginForm("Create", "AcceptanceQualityDefect", new AjaxOptions()
{
    OnSuccess = "ClearInput",
    HttpMethod = "Post",
    UpdateTargetId = "defect-list",
    InsertionMode = InsertionMode.Replace
}, new { @id = "frmID" })) 

frmID是表单的标识 我们调用JavaScript函数的名称为"ClearInput" <脚本type = " text / javascript”> 函数ClearInput() { //创建视图 $ (" # frmID ") . get (0) .reset (); } > < /脚本 如果这两项你都做对了,那么你将无法阻止它的工作……

其他回答

对于jQuery 1.6+:

$(':input','#myform')
  .not(':button, :submit, :reset, :hidden')
  .val('')
  .prop('checked', false)
  .prop('selected', false);

对于jQuery < 1.6:

$(':input','#myform')
  .not(':button, :submit, :reset, :hidden')
  .val('')
  .removeAttr('checked')
  .removeAttr('selected');

请看这篇文章: 使用jQuery重置多级表单

Or

$('#myform')[0].reset();

jQuery建议:

要检索和更改DOM属性,例如表单元素的选中、选中或禁用状态,请使用.prop()方法。

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

其中editPOIForm是表单的id属性。

经过测试和验证的代码:

  $( document ).ready(function() {
    $('#messageForm').submit(function(e){
       e.preventDefault();
    });
    $('#send').click(function(e){
      $("#messageForm")[0].reset();
    });
  });

Javascript必须包含在$(document)中。准备好了,而且必须符合你的逻辑。

我有个最简单的重置姿势的技巧

jQuery("#review-form")[0].reset();

$("#review-form").get().reset();

有什么理由不应该使用它吗?

$("#form").trigger('reset');