我很好地提交了联系表格。一切都很好,但当我提交时,我想清除所有字段详细信息。输入没有刷新。
我的JavaScript
$(document).ready(function(){
$('#buttonme').click(function(){
$.post("send.php", $("#myform").serialize(), function(response) {
$('#contactstatus').html(response);
//$('#success').hide('slow');
});
return false;
});
});
我该如何刷新我必须在myscript中添加的内容
尝试这样:
$('#myform').each(function(){
this.reset();
});
这应该完成工作:
$('input')
.val('')
.removeAttr('checked')
.removeAttr('selected');
<form>
<input type="text" />
<input type="reset" id="reset" />
<input type="button" id="buttonme" value="Submit"/>
</form>
$(document).ready(function () {
$("input:reset").hide();
$('#buttonme').click(function () {
$("input:reset").click();
});
});
正在运行的演示http://jsfiddle.net/cse_tushar/8URw4/
根据您的情况在您的屏幕上添加HTML
<input type="reset" id="reset" />
$(document).ready(function(){
$('#buttonme').click(function(){
$.post("send.php", $("#myform").serialize(), function(response) {
$('#contactstatus').html(response);
//$('#success').hide('slow');
$("input:reset").click();//add this to your code
});
return false;
});
});
或者您可以简单地使用
$('form').trigger('reset');