加载 ajax 内容后,我在重新绑定(bind) slimbox2 时遇到问题。我意识到我需要重新绑定(bind) ajax 加载上的函数,但我不知道该怎么做。我正在使用此代码生成外部内容。
$(document).ready(function() {
$('.content_box').hide();
$('.sf-menuUP a').click(function(){
$('.content_box').fadeIn('slow');
});
var hash = window.location.hash.substr(1);
var href = $('.sf-menuUP li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #content';
$('#content').load(toLoad)
}
});
$('.sf-menuUP li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content').fadeOut('fast',loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').fadeIn('normal',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
});
我尝试添加
// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
jQuery(function($) {
$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
});
});
到我的脚本底部,希望能重新加载它。但没有运气。我读过 livequery 可以工作,但我不知道如何/在哪里/做什么。
我快要绝望了。请问有人吗?
谢谢。
最佳答案
我看了一下liveQuery为你。这是您需要执行的操作:
$("a[rel^='lightbox']").livequery(function(){
$(this).slimbox({/* Put custom options here */}, null, function(el) {
return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
}), function() {
//remove slimbox? this is called when elements no longer match
}
});
关于JQuery slimbox 在 ajax 回调后重新绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/854130/