我希望在bootstrap中返回当前隐藏模式的元素ID。我似乎无法通过此代码找到捕获它的方法:
$(document).on('hide.bs.modal', function (e) {
// I want to know what the attr ID is of THIS modal being closed?
// I tried console.log(e) to see if I could find the reference but its not in the object?
});
目的是为所有模态设置此项,某些模态包含输入字段,如果更改为脏标志,我可以提醒用户如果关闭此模式可能会发生数据丢失。
答案 0 :(得分:1)
如果您在该处理程序函数中记录您收到的事件,您会注意到它们上面有一个包含实际模态的target
节点。所以获取id应该如下:
var id = e.target.id;
查看我设置的演示:
http://www.bootply.com/JvORc5bWvD
关闭时,您将在控制台中看到模态ID。
答案 1 :(得分:0)