我有3个div,
这将是模态
id =“ myModal”
其他div将是模态的内容-新建和编辑操作,因此:
id =“ new” data-view ='New-Operation'
id =“ edit” data-view ='Edit-Operation'
function init(){
var modal = document.getElementById("myModal");
modal.innerHTML = "";
modal.innerHTML = $("#new");
}
$("#myModal").on("[data-view='New-Operation'] hidden.bs.modal", function () {
});
$("#myModal").on("[data-view='Edit-Operation'] hidden.bs.modal", function () {
})
init();
为什么两个都被触发?
最佳答案
hidden.bs.modal是将被触发的事件类型
尝试更改此:
var modal = document.getElementById("myModal");
modal.innerHTML = "";
$("#myModal").attr('data-view','New-Operation');
modal.innerHTML = $("#new");
$("#myModal div[data-view='New-Operation']").on(" hidden.bs.modal", function () {
});
$("#myModal div[data-view='Edit-Operation']").on(" hidden.bs.modal", function () {
});
关于javascript - 当我关闭模式时,所有hidden.bs.close都会被触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51916209/