简体   繁体   English

点击提交按钮触发

[英]Trigger on click of submit button

I'm trying to trigger a short script click of the following submit button. 我试图触发以下提交按钮的短脚本单击。 It should add the "loading" css when the purchase button is clicked. 单击购买按钮时,它应添加“正在加载” css。 The code will be loaded using Googletagmanager only on this page. 仅在此页面上使用Googletagmanager加载代码。 The code I am currently attempting is: 我目前正在尝试的代码是:

<script>
 jQuery( document ).ready( function( $ ) {
$( '.form-row.place-order' ).click( function() {
$( this ).addClass( 'loading' );
});
});</script>

Here is the html 这是HTML

<div class="form-row place-order">
<input type="submit" class="button alt" 
name="woocommerce_checkout_place_order" id="place_order" value="Finalizar 
compra" data-value="Finalizar compra">
<input type="hidden" id="_wpnonce" name="_wpnonce" value="6df1de1da5"><input 
type="hidden" name="_wp_http_referer" value="/?wc-ajax=update_order_review">    
</div>    

I've also tried it with #place_order instead of .form-row.place-order however in both cases without sucess. 我也用#place_order而不是.form-row.place-order尝试过,但是在两种情况下都没有成功。 Does anybody have an idea what I can? 有人知道我能做什么吗? Thanks for your help. 谢谢你的帮助。 Best regards, 最好的祝福,

Your code works fine check it out. 您的代码可以正常运行。 I think you should check your css class is doing what you mean to do. 我认为您应该检查您的css类是否在做您想做的事情。

 .loading input{ color : white; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> jQuery( document ).ready( function( $ ) { $( '.form-row.place-order' ).click( function() { $( this ).addClass( 'loading' ); }); });</script> <div class="form-row place-order"> <input type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="Finalizar compra" data-value="Finalizar compra"> <input type="hidden" id="_wpnonce" name="_wpnonce" value="6df1de1da5"><input type="hidden" name="_wp_http_referer" value="/?wc-ajax=update_order_review"> </div> 

I think you should wait for DOM, and just use normal javascript like below Or maybe your submit is too fast and does not show the animation? 我认为您应该等待DOM,然后像下面那样使用普通的javascript,或者您的提交速度太快,并且不显示动画?

<script>
jQuery( document ).ready( function( $ ) {

    $('#place_order').click(function(e) {
       $(this).addClass('loading');
    });

})();
</script>

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

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