简体   繁体   English

如何使用jQuery javascript ..重设整个表格?

[英]how to reset the whole form using jquery javascript..?

i have a script to send email via Ajax php code is working well but i also want to reset form after send email here is my jquery code 我有一个脚本通过Ajax发送电子邮件,php代码运行良好,但我也想在发送电子邮件后重置表单,这是我的jquery代码

       <script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){

$('#slider-submit').click(function(){
    $('#success').text('Sending...');

$.post("send.php", $("#slider-form").serialize(),  function(response) {   
 $('#success').html(response);
 //$('#success').hide('slow');


});
return false;
$('#slider-submit')[0].reset();

});

});
</script>

please tell me how is it possible i also used reset method but not working at all 请告诉我怎么可能我也使用了重置方法,但根本不工作

You are almost near to your goal, you just need to change the order of your statements (first reset the form, and then return false) in your script, that is as follows. 您几乎快要实现目标了,您只需要在脚本中更改语句的顺序(首先重置表单,然后返回false),如下所示。

change 更改

return false;
$('#slider-submit')[0].reset();

to

$('#slider-submit')[0].reset();
return false;

Your reset line ( $('#slider-submit')[0].reset(); ) is after the return statement, so it is not called. 您的重置行( $('#slider-submit')[0].reset(); )在return语句之后,因此不会被调用。 Append it to the ajax success function (assuming that the form id is ´slider-submit´). 将其追加到ajax成功函数(假设表单ID为“ slider-submit”)。

$(document).ready(function(){
    $('#slider-submit').click(function(){
        $('#success').text('Sending...');

        $.post("send.php", $("#slider-form").serialize(),  function(response) {   
            $('#success').html(response);
            //$('#success').hide('slow');

            $('#slider-submit')[0].reset();
        });
        return false;

    });
});

There are different methods, one possible is to trigger the reset event. 有多种方法,一种可能是触发重置事件。

Assuming that your form id is ´slider-submit´ 假设您的表单ID是“滑块提交”

$('#slider-submit').trigger('reset');

In a normal scenario after posting ajax call using jquery. 在正常情况下,使用jquery发布ajax调用后。

$('#MyFormId').reset()

or

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

Hopefully it should work.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM