<分区>
标签 javascript jquery css ajax reset
<分区>
实时站点- http://onetieva.com/#contact
此表单是使用 Ajax 和 PHP 编程的。成功提交后,我想从输入框中隐藏用户输入的信息。
知道怎么做。
最佳答案
您可以使用 reset()
函数从字面上将表单重置
到它的原始状态。
如果您使用 ajax 提交表单...可以使用回调函数完成,但我建议使用 .done()
和 fail()
函数,以处理这两种情况。
所以,会是这样的:
$.post( "example_post_page.php", example_form_data )
.done(function() {
// Looks good
// Let the user know with a message and then, clears the form.
alert( "success" );
$('#form-contact')[0].reset();
// -------------------^ Same behavior as <input type="reset" /> element.
})
.fail(function() {
// Show some warning message
// Don't clear the data, so the user don't have to type all over again.
alert( "error" );
});
当然,这只是一个例子,可以改进,比如……用一个漂亮的模态框替换那些警报,为有错误的字段添加一些警告类,等等……
更多信息:jquery.post
关于javascript - ajax 提交后清除表单值。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23616354/