2011-04-08 82 views
0

即時通訊新的jquery/JavaScript和即時通訊嘗試做一個函數回調重新加載一個jQuery插件。什麼是適當的方式來做到這一點?函數回調重新加載一個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'); 
}); 
+1

你爲什麼要重新加載它的例子嗎?和什麼插件?一些示例代碼可以幫助你的原因 – jlarson 2011-04-08 00:48:43

+0

什麼觸發回調?你什麼時候想重新加載插件? – moe 2011-04-08 00:48:44

+0

該代碼似乎沒有任何與重新加載jQuery插件有關的問題。 – Pointy 2011-04-08 00:53:00

回答

0

我使用這個插件之前,我做的方式是我在負載功能加入我的代碼

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-技巧方法,那麼什麼都jQuery插件從應用正在加載的頁面應該已經被執行了。

像從CSS-技巧提供

<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