【发布时间】:2018-08-14 10:39:31
【问题描述】:
我有一个显示弹出窗口的按钮。我需要知道弹出窗口关闭后单击的按钮的 ID。警报显示没有 id 如何从第一个函数传递值 ID 以在第二个函数中使用它?
html 中带有要显示的弹出窗口的按钮:
<p class="stop_inv">
<span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>
Stop</p>
同一个html中的弹窗:
<div class="modal fade" id="confirm-stop-automated-popup" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog" style="width:370px;" role="document">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<form class="form-horizontal" method="post" id="stop_automated">
<div class="modal-body">
<div class="row">
<h1 class="center" style="font-size:100%;">
Do you wish to close them immediately ?
</h1>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" name="ok" data-dismiss="modal" id="confirm-stop-button">Ok</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" id="cancel-delete-button">Cancel</button>
</div>
</form>
</div>
</div>
</div>
我在 javascript 中的函数:(显示了弹出窗口,但问题是我不知道点击了弹出窗口中的哪个按钮,应该在第二个函数中传递 var 信息以使用它。
$('.automated-orders-list .stop').on('click', function() {
var $button = $(this);
var info = $button.closest('.data').attr('data-order-id');
$('#confirm-stop-automated-popup').modal('show');
e.preventDefault();
return;
});
第二个弹出窗口知道点击了哪个按钮不起作用:
$('#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);
});
});
【问题讨论】:
标签: javascript jquery html django