Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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 弹出窗口的显示id按钮不';t函数_Javascript_Jquery_Html_Django - Fatal编程技术网

Javascript 弹出窗口的显示id按钮不';t函数

Javascript 弹出窗口的显示id按钮不';t函数,javascript,jquery,html,django,Javascript,Jquery,Html,Django,我有一个显示弹出窗口的按钮。我需要知道弹出窗口关闭后单击的按钮的id。将显示不带id的警报 如何将第一个函数的值ID传递给第二个函数 html中的按钮,弹出窗口显示: <p class="stop_inv"> <span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Stop</p> 第二个用于弹出窗口以了解单击哪个按钮的javascript不起作用: $('

我有一个显示弹出窗口的按钮。我需要知道弹出窗口关闭后单击的按钮的id。将显示不带id的警报 如何将第一个函数的值ID传递给第二个函数

html中的按钮,弹出窗口显示:

<p class="stop_inv">
<span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>
Stop</p>
第二个用于弹出窗口以了解单击哪个按钮的javascript不起作用:

$('#confirm-stop-automated-popup .modal-footer button').on('click', function(event) {

    var $button = $(event.target); // The clicked button

    $(this).closest('.modal').one('hidden.bs.modal', function() {
        // Fire if the button element 
        alert('The button that closed the modal is: ', $button);
    });

});

如果你的主要目标只是显示哪个按钮是点击,你可以使用下面的代码来实现这一点

$('#confirm-stop-automated-popup .modal-footer button').on('click',
    function() {
        console.log('The button that closed the modal is: ' + this.innerText);
        //alert('The button that closed the modal is: ' + this.innerText);
    });
当你点击一个按钮时,你已经按住了按钮对象。通过
关键字,您可以读取该对象属性。您不需要通过
event.target
显式查找目标按钮

$('#confirm-stop-automated-popup .modal-footer button').on('click',
    function(event) {
        var $button = this.innerText;

        $(this).closest('.modal').one('hidden.bs.modal', function() {
            // Fire if the button element 
            console.log('The button that closed the modal is: ' + $button);
        });

    });

非常感谢你的帮助!但是,我如何知道所单击按钮的id呢?
这个.id将给出按钮id。我在其中编写了innerText,将其替换为id.Welcome。如果我的答案解决了您的问题,请单击大复选框接受它作为答案。这将有助于我们(出资人)建立回购协议。在这个社区,当然。。我还有一个问题,非常感谢你的帮助。我有一个名为info的变量,我需要将它传递给第二个函数以使用它。我该怎么做?问题已编辑,谢谢您的时间!因为它是一个局部变量,所以可以在第二个
func()
中复制粘贴相同的变量。如果您想重用同一个,请将其改为全局。
$('#confirm-stop-automated-popup .modal-footer button').on('click',
    function() {
        console.log('The button that closed the modal is: ' + this.innerText);
        //alert('The button that closed the modal is: ' + this.innerText);
    });
$('#confirm-stop-automated-popup .modal-footer button').on('click',
    function(event) {
        var $button = this.innerText;

        $(this).closest('.modal').one('hidden.bs.modal', function() {
            // Fire if the button element 
            console.log('The button that closed the modal is: ' + $button);
        });

    });