我是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');
});
答案 0 :(得分: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-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