JQuery slimbox 在 ajax 回调后重新绑定(bind)

标签 jquery ajax callback slimbox

加载 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/

相关文章:

javascript - 如何在 jQuery/js 中使用 if 语句更改变量值

jquery - 关闭 Bootstrap 模态窗口将关闭模态窗口之外的弹出窗口

java - 如何发送自定义 java 类对象作为对 java servlet 中 ajax 调用的响应并在 javascript 中检索它?

jquery - 使用 Ajax 和 ASP.NET 中的 Web 服务从 SQL Server 数据库下载文件

jquery - 简单的 jQuery 回调在 IE 中中断

javascript - 将 Jquery 单击处理程序添加到动态加载的内容

javascript - 如何在 javaScript 中获取动态 div 宽度

javascript - 使用 GET 方法通过 AJAX 成功提交表单后更改 url

javascript - 如何在回调之外赋值

c++ - COM 对象中的回调