2009-12-05 58 views
3

我有一个表单使用ajax发布并重新加载下面的div。表单提交后的明文形式

当按下提交按钮时,我需要清除文本框。

<form name=goform action="" method=post> 
<textarea name=comment></textarea> 
<input type=submit value=submit> 
</form> 

回答

16

textarea添加id

<textarea name='comment' id='comment'></textarea> 

钩到提交过程并添加:

$('#comment').val(''); 
0

发布后,只需调用这个:

$("textarea[name=comment]").val(""); 

或改善,一个ID分配给您的textarea:

<form name=goform action="" method=post> 
<textarea id="txtComment" name="comment"></textarea> 
<input type=submit value=submit> 
</form> 

并在发布后使​​用此:

$("#txtComment").val(""); 
1

如果你不使用jQuery(这是需要上面给出的解决方案)可以代替

$("#txtComment").val(""); 

document.getElementById("txtComment").value = ""; 
+0

哦,只是实现了问题被标记为“jquery”,所以可能你正在使用它:) – Ozzy

0
<script> 
    function testSubmit() 
    { 
     var x = document.forms["myForm"]["input1"]; 
     var y = document.forms["myForm"]["input2"]; 
     if (x.value === "") 
     { 
      alert(' fill!!'); 
      return false; 
     } Blockquote 
     if(y.value === "") 
     { 
      alert('plz fill the!!'); 
      return false; 
     } 
     return true; 
    } 
    function submitForm() 
    { 
     if (testSubmit()) 
     { 
      document.forms["myForm"].submit(); //first submit 
      document.forms["myForm"].reset(); //and then reset the form values 
     } 
    } </script> <body> 
    <form method="get" name="myForm"> 

     First Name: <input type="text" name="input1"/> 
     <br/> 
     Last Name: <input type="text" name="input2"/> 
     <br/> 
     <input type="button" value="Submit" onclick="submitForm()"/> 
    </form> 

</body>