在jquery中提交后清除表单输入字段

dnph8jn4  于 2024-01-07  发布在  jQuery
关注(0)|答案(3)|浏览(192)

我尝试使用jquery提交表单。表单提交正确,但提交后不清除表单。
下面是我的jquery代码

  1. <script type="text/javascript">
  2. $(document).ready(function(){
  3. $("#save").click(function(){
  4. $("#myform").submit();
  5. $("#myform")[0].reset();
  6. });
  7. });
  8. </script>

字符串
这是我表格

  1. <form action="http://localhost/newsletter/index.php/email/send" method="post" accept-charset="utf-8" id="myform" name="myforms">
  2. <p>
  3. <label for="name">Email Address </label>
  4. <input type="text" name="email" id="email" value="<?php echo set_value('email');?>">
  5. <input type="button" value="Go" id="save"></p>
  6. </form>


我只是想提交后清除表单,但它不能重置字段,数据已提交,仍留在该领域。有什么建议,请??

wixjitnu

wixjitnu1#

这是因为您使用了CodeIgniter的函数set_value。它将包含提交的电子邮件。您可能使用了控制器中的表单验证库,在那里添加一些逻辑,以便您的视图“知道”验证成功时不应该显示电子邮件。

yc0p9oo0

yc0p9oo02#

你有没有试过用$("#myform").get(0).reset();代替$("#myform")[0].reset();

bn31dyow

bn31dyow3#

你可以做的。

  1. document.getElementById("myform").reset();

字符串

相关问题