繁体   English   中英

函数回调以重新加载jQuery插件

[英]function callback to reload a jquery plugin

我是jquery / javascript的新手,我试图进行函数回调以重新加载jquery插件。 什么是合适的方法呢?

$(function() {

    var newHash      = "",
    $mainContent = $("#main-content"),
    $el;

    $("nav").delegate("a", "click", function() {
        window.location.hash = $(this).attr("href");
        return false;
    });

    $(window).bind('hashchange', function(){
        newHash = window.location.hash.substring(1); 
        if (newHash) {
            $mainContent
            .find("#guts")
            .fadeOut(200, function() {
                $mainContent.hide().load(newHash + " #guts", function() {
                    $mainContent.fadeIn(200, function() {
                        /*rebind plugin*/
                    });
                    $("nav a").removeClass("current");
                    $("nav a[href="+newHash+"]").addClass("current");
                });
            });
        };
    });    

    $(window).trigger('hashchange');
});

我以前用过这个插件,我做的方法是在加载函数中添加代码

if (newHash) {
        $mainContent
            .find("#guts")
            .fadeOut(200, function() {
                $mainContent.hide().load(newHash + " #guts", function() {
                    /* load in javascript you want to apply to the new content being loaded */
                    $mainContent.fadeIn(200, function() {
                    /*rebind plugin*/   
                    });
                    $("nav a").removeClass("current");
                    $("nav a[href="+newHash+"]").addClass("current");
                });
            });


    }

另外,如果您使用CSS-Tricks方法,那么应该已经执行了从正在加载的页面应用的jquery插件。

就像在css-tricks提供的示例中一样

<html>
    <head>
        <script jquery.js file here>
    <body>
        <div id="wrap">
         // the stuff here will loaded to the page retrieving it already spiced up by jquery from the script in the head

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM