[英]Clear textfield in a form after submit
我有以下表格:
<form onsubmit="chat.sendMsg(); return false;">
<label for="msg" style="float:left">Message:</label>
<input type="text" id="msg" name="msg" autofocus="true" placeholder="Type Your Meassage Here" />
<input type="submit" />
</form>
以及附帶的JavaScript:
//For sending message
this.sendMsg=function(){
msg=document.getElementById("msg").value;
chatZone.innerHTML+='<div class="chatmsg"><b>'+name+'</b>: '+msg+'<br/></div>';
oldata='<div class="chatmsg"><b>'+name+'</b>: '+msg+'<br/></div>';
this.ajaxSent();
return false;
};
所有的作品,但當我提交表格時,文本保留在表格中。 我按下Enter /單擊“提交”后如何清除此文本字段?
PS我不使用jQuery
使用此document.getElementById("msg").value = '';
: document.getElementById("msg").value = '';
this.sendMsg=function(){
msg=document.getElementById("msg").value;
chatZone.innerHTML+='<div class="chatmsg"><b>'+name+'</b>: '+msg+'<br/></div>';
oldata='<div class="chatmsg"><b>'+name+'</b>: '+msg+'<br/></div>';
this.ajaxSent();
document.getElementById("msg").value = '';//here
return false;
};
您可以添加此
document.getElementById("msg").value='';
在以下語句之前:
return false;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.