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

dnph8jn4  于 5个月前  发布在  jQuery
关注(0)|答案(3)|浏览(72)

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

<script type="text/javascript">
    $(document).ready(function(){   
        $("#save").click(function(){    
            $("#myform").submit();
            $("#myform")[0].reset();        
         });    

    });             
</script>

字符串
这是我表格

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

        <input type="button" value="Go" id="save"></p>

</form>


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

wixjitnu

wixjitnu1#

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

yc0p9oo0

yc0p9oo02#

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

bn31dyow

bn31dyow3#

你可以做的。

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

字符串

相关问题