jQuery的.load()函数中断从.load开封后模态()完成 [英] jQuery's .load() function breaks modal from opening after .load() completes
问题描述
我使用jQuery的 .load()
一>方法和加载页面片段的。下面是我目前的code:
I am using jQuery's .load()
method and Loading Page Fragments. Below is my current code:
$("#submit").click(function() {
$("#results").load('/ajax/box/ #box');
});
这code是一个MODA,当 a.ajax模态
点击时调用。问题是,当 .load()
完成后, a.ajax模态
在 #box
被装入 #results
工作不......不不开的模式,而是只是打开了新的一页。它看起来像 #box
没有绑定/连接到任何事件处理程序的内容。
This code is in a moda, which is called when a.ajax-modal
is clicked. The problem is that when .load()
has completed, the a.ajax-modal
in #box
that was loaded into #results
is not working... it doesn't not open the modal but instead just opens a new page. It seems like the contents of #box
are not bound/attached to any event handlers.
下面是正在发生的事情的概要:
Here is an outline of what is happening:
- 加载页
- 点击
a.ajax模态
和模态节目 - 在模式提交表单,运行
。点击()
模态 功能
- 在
#results
内容的网页刷新 - 点击新
a.ajax模态
这是在#results
加载,但语气不显示
- Load page
- Click on
a.ajax-modal
and modal shows - Submit form in modal, run
.click()
function in modal - Content in
#results
on page refreshes - Click on new
a.ajax-modal
that was loaded in#results
but modal does not show
为什么模态不开放后 .load()
完成?
Why is the modal not opening after .load()
is complete?
推荐答案
没有事件已被添加到您的元素,因为事件被添加在文档已准备就绪。您需要使用。对()的jQuery方法prevent这一点。
No event has been added to your element because events are added when the document is ready. You need to use .on() method of jQuery to prevent this.
$(function()
$(document).on('click', 'a.ajax-modal', function() {
// Your code here.
});
});
因此事件被添加到文件
而不是元素本身。
这篇关于jQuery的.load()函数中断从.load开封后模态()完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!