Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击按钮时,警报未触发_Javascript_Jquery_Woocommerce - Fatal编程技术网

Javascript 单击按钮时,警报未触发

Javascript 单击按钮时,警报未触发,javascript,jquery,woocommerce,Javascript,Jquery,Woocommerce,我需要在“下订单”按钮上发出警报。 当我在下面输入id为“place_order”的代码时,它不起作用。但是,当我用任何其他元素id更改此id并单击此处时,它会工作 单击以下按钮时,我需要此警报才能工作: jQuery(文档).ready(函数($){ $(函数(){ $(“#下订单”)。单击(函数(){ 警报(“这是一条测试消息…请忽略此消息”); }); }); }); 使用WorldPay安全支付这是您对链接按钮或普通按钮的操作方式: $(document).ready(functio

我需要在“下订单”按钮上发出警报。 当我在下面输入id为“place_order”的代码时,它不起作用。但是,当我用任何其他元素id更改此id并单击此处时,它会工作

单击以下按钮时,我需要此警报才能工作:

jQuery(文档).ready(函数($){
$(函数(){
$(“#下订单”)。单击(函数(){
警报(“这是一条测试消息…请忽略此消息”);
});
});
});


使用WorldPay安全支付
这是您对链接按钮或普通按钮的操作方式:

$(document).ready(function(){
    $('#place_order').click(function() {
        alert("This is a test message... please ignore this.");
    });
});
$(document).ready(function(){
    $('#place_order').click(function() {
        alert("This is a test message... please ignore this.");
    });
});
但是您使用的是提交按钮,因此表单已提交,您无法看到消息。 如果需要,可以使用以下方法停止表单提交:

$(document).ready(function(){
    $('form').on('submit', function(event){
       event.preventDefault();
       event.stopPropagation();
       alert("Form Submission prevented/stopped.");
    });

    $('#place_order').click(function() {
        alert("This is a test message... please ignore this.");
    });
});
$(document).ready(function(){
    $('form').on('submit', function(event){
       event.preventDefault();
       event.stopPropagation();
       alert("Form Submission prevented/stopped.");
    });

    $('#place_order').click(function() {
        alert("This is a test message... please ignore this.");
    });
});

希望它能帮助您

您的代码一定是这样的,您可以检查您缺少了什么

<!DOCTYPE html>
<html>
        <link rel="stylesheet" type="text/css" href="jQuery_functions.css">
         <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<button type="submit" class="place_order" name="woocommerce_checkout_place_order" id="place_order" value="Place order" data-value="Place order">Pay securely with WorldPay</button>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
        $('#place_order').click(function(){ alert("This is a test message... please ignore this.");
    });
});
 </script>
</html>

用WorldPay安全支付
$(文档).ready(函数(){
$(“#下订单”)。单击(函数(){alert(“这是一条测试消息……请忽略此消息”);
});
});

希望我能帮忙

这是链接按钮或普通按钮的操作方式:

$(document).ready(function(){
    $('#place_order').click(function() {
        alert("This is a test message... please ignore this.");
    });
});
$(document).ready(function(){
    $('#place_order').click(function() {
        alert("This is a test message... please ignore this.");
    });
});
但是您使用的是提交按钮,因此表单已提交,您无法看到消息。如果需要,可以使用以下方法停止表单提交:

$(document).ready(function(){
    $('form').on('submit', function(event){
       event.preventDefault();
       event.stopPropagation();
       alert("Form Submission prevented/stopped.");
    });

    $('#place_order').click(function() {
        alert("This is a test message... please ignore this.");
    });
});
$(document).ready(function(){
    $('form').on('submit', function(event){
       event.preventDefault();
       event.stopPropagation();
       alert("Form Submission prevented/stopped.");
    });

    $('#place_order').click(function() {
        alert("This is a test message... please ignore this.");
    });
});

代码片段本身可以工作,是否有其他干扰?你在页面上看到任何控制台错误吗?没有,控制台中没有任何内容,只要我单击那里,它就会导航到WorldPay…好的,按钮显然在表单中,提交正在进行。你需要先取消提交。这是一个WooCommerce的签出按钮,我认为它正在进行ajax调用,因为当我点击按钮时,我看到按钮内旋转的动画,然后它会导航到其他页面。。。