colorbox 不支持 Ajax
我正在尝试从 ajax 调用动态加载的内容中打开 colorbox。单击“下一步”时,它会在页面上加载另一个块,单击该块时,应打开颜色框覆盖。
但是对于第一个项目颜色框打开,然后我无法将颜色框与链接绑定。
请看,我用于绑定 colorbox 的 javascript 代码是:
$(document).ready(function() {
$('#recommended-app-wrapper .app_download_link').each(function() {
$(this).colorbox({
href: $(this).attr('href'),
iframe: false,
onComplete: function() {
// Tooltip
$('#modal a.link_tooltip').each(function() {
$(this).click(function() {
return false;
});
var content = $(this).next('.hidden').html();
$(this).aToolTip({
tipContent: content,
fixed: true,
clickIt: false,
xOffset: -180,
yOffset: 30
});
});
// Clear-Default
$('#modal input.clear-default').clearDefault();
}
});
});
});
调用内容页面的 JSP 代码是
<dsp:a page="/fragments/product_app_download.jsp" iclass="custom custom-blue-smapp_download_link get-app">
<dsp:param name="id" param="element.id"/>
Get app
</dsp:a>
请参阅主页,从中进行 ajax 调用,并加载用户可以从中单击并打开 colorbox 的块。我已经截取了代码的屏幕截图。
我认为,问题是,我将颜色框绑定在document.ready 仅被调用一次,然后单击“下一个”后,它不会将我的下一个项目绑定到颜色框。
请帮忙。
谢谢
I am trying to open colorbox from dynamically loaded contents from ajax calls. On click of next it loads another block on the page and on clicking on that block, colorbox overlay should be opened.
But for the first item colorbox is opened, then after i am not able to bind colorbox with the link.
Please see, my javascript code which is used to bind colorbox is:
$(document).ready(function() {
$('#recommended-app-wrapper .app_download_link').each(function() {
$(this).colorbox({
href: $(this).attr('href'),
iframe: false,
onComplete: function() {
// Tooltip
$('#modal a.link_tooltip').each(function() {
$(this).click(function() {
return false;
});
var content = $(this).next('.hidden').html();
$(this).aToolTip({
tipContent: content,
fixed: true,
clickIt: false,
xOffset: -180,
yOffset: 30
});
});
// Clear-Default
$('#modal input.clear-default').clearDefault();
}
});
});
});
JSP code which calls the content page is
<dsp:a page="/fragments/product_app_download.jsp" iclass="custom custom-blue-smapp_download_link get-app">
<dsp:param name="id" param="element.id"/>
Get app
</dsp:a>
Please see the main page, from where the ajax call is being made and it loads the block from which user can click and open the colorbox. I have taken the screenshot of the code.
I think, the issue is , i am binding the colorbox on document.ready which is called only one time, then after on clicking of next it doesnt bind my next item to colorbox.
Kindly help.
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 jquery .live() 函数将事件绑定到尚未创建的元素它。我想这就是你可能需要的。
You can use the jquery .live() function to bind events to elements that haven't even been created it. I think this is what you might need.
像这样思考你的问题:在页面加载时,最初 DOM 已准备好,并且为选择器初始化了 colorbox AJAX 调用页面的一个新部分,其中包含一些位于 colorbox 选择器列表中的 DOM 元素,但没有被注意到,因为它在 JavaScript 读取选择器后加载到页面中。
现在尝试这个,因为它会监视所有现有的和新的“.app_download_link”的“#recommished-app-wrapper”:
这种方式不是等待让插件监视事件,而是使用 .delegate() 监视事件,并且即时执行颜色框...
onComplete 函数可能不完全是您所需要的,但您明白了。
Think of your problem like this: On page load initially the DOM is ready, and colorbox is initilized for the selector AJAX calls a new piece of the page with some DOM element that is in the colorbox selector list, but isn't noticed because it loaded into the page after the selector was read by the javascript.
now try this, as it watches "#recommended-app-wrapper" for all, existing and new ".app_download_link":
This way instead of waiting for letting the plugin watch for the event, watch the event with .delegate(), and execute the colorbox on the fly...
The onComplete function may not be exactly what you need, but you get the idea.