[英]How to clean form after submitting ajax?
First of all: I tried to search the answer in the web and I found like 20 examples of code. 首先:我尝试在网上搜索答案,发现了20个示例代码。 But I failed.
但是我失败了。 still nothing is working.
仍然没有任何工作。
I'm making a simple chat and i need to clean my form after submitting data via ajax. 我正在进行简单的聊天,我需要通过ajax提交数据后清理表单。 Here is the code:
这是代码:
<form id="ChatFrom" class="chatMessageField" action="Amess.php" method="post">
<input class="chatMessageField" type="text" name="mess" /><br />
<input class="chatMessageBtn" type="button" value="Отправить" onclick="SendForm();" />
</form>
<script type="text/javascript" src="http://scriptjava.net/source/scriptjava/scriptjava.js"></script>
<script type="text/javascript">
function SendForm() {
$$f({
formid:'ChatFrom',
url:'Amess.php',
});
}
</script>
$("#ChatFrom")[0].reset()
// or
$("#ChatFrom").get(0).reset()
You could do it like this: 您可以这样做:
function SendForm() {
$.post( "Amess.php", function( data ) {
resetFields();
});
}
function resetFields(){
$(':input')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
}
Hope it helps! 希望能帮助到你!
$(".chatMessageField").val(''); $(“。chatMessageField”)。val(''); is a simple way, but you have to do it to all the fields individually.
这是一种简单的方法,但是您必须对所有字段分别进行操作。 A better solution would be to give all of your inputs a class name that is the same and clear them all at once.
更好的解决方案是给所有输入一个相同的类名,并立即清除它们。 Or just use jquery reset()
或者只是使用jquery reset()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.