简体   繁体   English

提交时清除输入字段

[英]Clear input fields on submit

I am trying to clear my input fields after the user clicks on submit with MailChimp, although I seem to be having problems with it.在用户点击使用 MailChimp 提交后,我试图清除我的输入字段,尽管我似乎遇到了问题。

I have tried a lot of options to make it work and nothing does the trick.我已经尝试了很多选择来使它工作,但没有任何办法。 Can you help me?你能帮助我吗?

Thanks, in advance.提前致谢。

HTML HTML

<div class="mc-field-group">
    <div class="row">
        <div class="col-sm-6 col-md-6">
            <input type="text" placeholder="Type your name here..." 
                   value="" 
                   name="NOME" class="form-control input-box required pull- 
                   right" id="mce-NOME">
        </div>
        <div class="col-sm-6 col-md-6">
            <input type="text" placeholder="Type your email here..." 
                   value="" name="EMAIL" class="form-control input-box 
                   required pull-left" id="mce-EMAIL">
        </div>
    </div>
</div>
<div class="mc-field-group">
    <div class="row">
        <div class="col-sm-12">
            <textarea limit="1000" placeholder="Type your message here..." 
                      style="height: 100px; width: 500px;" value="" 
                      name="MENSAGEM" class="form-control textarea-box required" 
                      id="mce-MENSAGEM">
            </textarea>
        </div>
    </div>
</div>

JS JS

$('#mc-embedded-subscribe-form').ajaxChimp({
callback: mailchimpCallback,
url: ""  
});

function mailchimpCallback(resp) {
 if (resp.result === 'success') {
    $('.subscription-success').html('<span class="icon_check_alt2"></span>' + ' Agradecemos por sua mensagem.<br />Entraremos em contato em breve.').fadeIn(1000);
    $('.subscription-error').fadeOut(500);

} else if(resp.result === 'error') {
    $('.subscription-error').html('<span class="icon_close_alt2"></span>' + 'Oops... Houve um erro ao tentar enviar sua mensagem.<br/>Por favor, tente novamente em alguns minutos.').fadeIn(1000);
  }  
}

You can use $(':input').val('');您可以使用$(':input').val(''); and $('textarea').val('');$('textarea').val('');

 $("#reset").click(function(){ $(':input').val(''); $('textarea').val(''); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="mc-field-group"> <div class="row"> <div class="col-sm-6 col-md-6"> <input type="text" placeholder="Type your name here..." value="" name="NOME" class="form-control input-box required pull- right" id="mce-NOME"> </div> <div class="col-sm-6 col-md-6"> <input type="text" placeholder="Type your email here..." value="" name="EMAIL" class="form-control input-box required pull-left" id="mce-EMAIL"> </div> </div> </div> <div class="mc-field-group"> <div class="row"> <div class="col-sm-12"> <textarea limit="1000" placeholder="Type your message here..." style="height: 100px; width: 500px;" value="" name="MENSAGEM" class="form-control textarea-box required" id="mce-MENSAGEM"> </textarea> </div> </div> </div> <input type="button" id="reset" value="Reset">

You can simply put it in your success handler, something like你可以简单地把它放在你的成功处理程序中,比如

$('.mc-field-group input, .mc-field-group textarea').val('')

should do the trick.应该做的伎俩。

If you have the fields in a form, you can use reset on the form如果您有表单中的字段,则可以在表单上使用重置

$('#formId')[0].reset();
$('.mc-field-group').find('input,textarea').val('')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM