jQuery Form插件重置()

时间:2014-04-14 01:37:52

标签: php jquery ajax forms

我正在使用http://malsup.com/jquery/form/

非常简单,如何提交它然后重置我的表单?我对ajax几乎一无所知

4 个答案:

答案 0 :(得分:0)

使用jQuery - 这将重置所有文本字段(文本和密码)。如果您需要重置其他字段(复选框...),您还需要清除它们:

    $(document).ready(function() { 
       // bind 'myForm' and provide a simple callback function 
        $('#myForm').ajaxForm(function() { 
            alert("Thank you for your comment!"); 
            $('#myForm').find("input[type=text] input[type=password], textarea").val("");
        }); 
    }); 

答案 1 :(得分:0)

$(".submit").click(function() {
    $(this).closest('myForm').find("input[type=text], textarea").val("");
});

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

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

答案 2 :(得分:0)

您可以使用HTML DOM Form reset()函数:

用法


...
// Selects the first (index 0) #myForm element and calls the reset method
// (the reset method is available to any HTML DOM form element)
$('#myForm')[0].reset();
...

链接


w3 documentation

w3schools documentation

答案 3 :(得分:0)

在您的ajax通话提交或成功后,请添加以下内容:

$("#form").submit(function(){
    //your ajax call
    $("#forum")[0].reset();// or document.getElementById("forum").reset();
}

或:

$.ajax({
    ...
    success: function(...){
        $("#forum")[0].reset();// or document.getElementById("forum").reset();
    }
});
相关问题