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

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

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


当前回答

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

应该可以工作

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

其他回答

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

应该可以工作

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

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

$("#form").trigger('reset');
$('form').submit(function() {

    var el = $(this);

    $('<button type="reset" style="display:none; "></button>')
        .appendTo(el)
        .click()
        .remove()
    ;

    return false;

});

使用jQuery实现正常复位函数

setTimeout("reset_form()",2000);

并把这个函数写出来的网站jQuery文档就绪

<script>
function reset_form()
{
    var fm=document.getElementById('form1');
    fm.reset();
}
</script>
$(document).ready(function() {
    $('#reset').click(function() {
    $('#compose_form').find("input[type=text] , textarea ").each(function() {
    $(this).val('');
   });
  });
});