Javascript 弹出窗口的显示id按钮不';t函数
我有一个显示弹出窗口的按钮。我需要知道弹出窗口关闭后单击的按钮的id。将显示不带id的警报 如何将第一个函数的值ID传递给第二个函数 html中的按钮,弹出窗口显示: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不起作用: $('
<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);
});
});