簡體   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