[英]jQuery events are not bind in loaded Bootstrap modal window
Trying to load dynamical content into Bootstrap modal with this code: 尝试使用以下代码将动态内容加载到Bootstrap模式中:
$('body').on('click', '.time-estimation', function () {
var taskId = $(this).data("task_id");
$("#modal-content").load("/tasks/estimation?task_id=" + taskId, function () {
$('#myModal').modal({show: true, keyboard: true, backdrop: true});
});
});
it works and modal window is displayed. 它可以工作并显示模式窗口。 But in loaded content there is another jQuery code, that is not binded: 但是在加载的内容中,还有另一个未绑定的jQuery代码:
$(document).ready(function () {
$("#TaskEstimationTimeForm").submit(function (event) {
event.preventDefault();
});
});
Why is not triggered this submit
event? 为什么不触发此submit
事件?
$(document).ready
is only triggered when a document is initially loaded in a window or iframe. 仅当文档最初加载到窗口或iframe中时,才触发$(document).ready
。 In your case you're pulling HTML directly in an element, and that even will not be fired. 在您的情况下,您是直接在元素中提取HTML,甚至不会被触发。 You don't need it though, you should just be able to do: 虽然您不需要它,但是您应该能够:
$("#TaskEstimationTimeForm").submit(function(event) {
event.preventDefault();
});
You can do this as it is working for me 您可以这样做,因为它对我有用
$('#myModal').modal({show: true, keyboard: true, backdrop: true})
.one('submit','#TaskEstimationTimeForm',function(){
//your stuff on event here
})
Hope it helps 希望能帮助到你
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.