javascript 提交jquery后清除表单数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17242192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
clear form data after submit jquery
提问by user2510039
How do I clear a form data once the submit succeed in jquery?
在jquery中提交成功后如何清除表单数据?
$(document).ready(function () {
$('#submit').click(function () {
$.ajax({
type: "POST",
url: 'final.php',
data: "user=" + $('#user').val() + "&comment=" + $('#comment').val(),
success: function (data) {
$('#status').html(data);
}
});
});
});
HTML... I need to clear the form data once the form is submitted....Any help would be appreciated.
HTML...一旦提交表单,我需要清除表单数据....任何帮助将不胜感激。
<input type="text" name="user" id="user">
<input type="text" name="comment" id="comment">
<input name="submit" type="submit" id="submit">
<div id="status">
回答by Nick B
you can try :-
你可以试试 :-
$('#formId').trigger("reset");
回答by Sushanth --
$('form').find('input[type=text]').val('')
should do
$('form').find('input[type=text]').val('')
应该做
Call this in the success callback of your Ajax
在 Ajax 的成功回调中调用它