我像这样以编程方式调用引导模式
$('#confirmModal').modal()
但是当我这样做时,“事件”在:
$('#confirmModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
})
没有“relatedTarget”,但我需要它。如何使用 $('#confirmModal').modal()
传递它最佳答案
您不能设置relatedTarget
,它是事件的只读属性。 show.bs.modal
是顺便说一句,由引导模式本身触发,所以无论哪种方式你都会迷路。
但为什么不以编程方式触发模态触发按钮的 click
事件,它与调用 modal()
完全相同,然后出现 relatedTarget
:
$("#button").click();
假设您已经像这样形成良好的“模态触发按钮”:
<button id="button" data-toggle="modal" data-target="#confirmModal">show modal</button>
关于twitter-bootstrap-3 - 当我以编程方式调用它时如何将参数传递给模态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34242445/