【发布时间】:2019-01-06 01:51:35
【问题描述】:
我有一个引导模式表单,其中包含要跟踪的项目列表。如果选中,则有一个全部切换框可以选择/取消选择列表中的所有项目。每次我显示我不理解的模式时,都会调用一次 jquery 函数。 第一次打开modal,jquery函数被调用。 第二次打开modal,jquery函数被调用了两次。 第三次打开modal,jquery函数被调用了3次。 等等。 为什么每次打开模式时都会调用一次此复选框功能? jquery 是否将事物推送到某处的某种类型的堆栈上? 如果用户选择了所有要检查的项目,我想要做的是弹出一个警报。但我不希望他/她收到多个警报。代码如下:
$('#realTimeModal').on('show.bs.modal', function (e) {
var modal = $(this)
console.log('controller-1253: realTimeModal handler');
//first, clear out any previous layers
clearLayers();
console.log('show_realtime, updatePositions: ', updatePositions );
clearInterval(updatePositions);
/*
* Check to see if the 'Toggle All' checkbox is checked. If so
* either select all checkboxes or deselect them.
*/
$("#check_rt").change(function () {
console.log('==================================');
console.log('===== in #check_rt =========');
console.log('==================================');
var checked = $(this).prop('checked');
if (checked == true) {
$.each($("input[class='form-check-input callSign_checkbox-rt']"), function () {
$(this).prop('checked', true);
});
trackAll = 'true';
}
else {
$.each($("input[class='form-check-input callSign_checkbox-rt']"), function () {
$(this).prop('checked', false);
});
trackAll = 'false';
}
//if ( trackAll == 'true' )
//alert('If you select all aircraft, breadcrumbs will not be displayed.');
});
}) // $('#realTimeModal').on('show.....)
如果用户选中全选复选框,我想要做的只是弹出警报。但我只想要一个警报,而不是打开模式时的警报数量。我在这里缺少 jquery 的基本内容吗?
谢谢.....
【问题讨论】:
标签: jquery bootstrap-4 event-handling