0
我想讓我的wordpress內部鏈接出現在內容div中,而不是進行正常的頁面重新加載。淡入/淡出工作正常,但div內容不會改變。 Firebug顯示沒有錯誤,所有內部鏈接現在只添加「#/」到頁面鏈接,我如何確保鏈接被正確添加回jQuery中? 由於提前,jquery鏈接淡入/淡出
PS,我下面的「CSS-招數:ajaxing一個WordPress主題爲」視頻是否有幫助,
$(function() {
$(".home li.home").removeClass("home").addClass("current_page_item");
var $mainContent = $("#content"),
URL = '',
siteURL = "http://" + top.location.host.toString(),
$internalLinks = $("a[href^='"+siteURL+"']"),
hash = window.location.hash,
$el, $allLinks = $("a");
if (hash) {
$mainContent.animate({ opacity: "0.1" });
$(".current_page_item").removeClass("current_page_item");
$("a[href="+hash+"]").addClass("current_link").parent().addClass("current_page_item");
hash = hash.substring(1);
URL = hash + " #content";
$mainContent.load(URL, function() {
$mainContent.animate({ opacity: "1" });
});
}
$internalLinks.each(function() {
$(this).attr("href", "#" + this.pathname);
}).click(function() {
$mainContent.animate({ opacity: "0.1" });
$el = $(this);
$(".current_page_item").removeClass("current_page_item");
$allLinks.removeClass("current_link");
URL = $el.attr("href").substring(1);
URL = URL + " #content";
$mainContent.load(URL, function() {
$el.addClass("current_link").parent().addClass("current_page_item");
$mainContent.animate({ opacity: "1" });
});
});
});
您是否嘗試輸出'this.pathname'?因爲我很確定它是未定義的。因此解釋了爲什麼最終只有'#'作爲鏈接。 – Kevin 2011-03-13 07:36:11
這看起來不錯,路徑名不顯示,應該包括在jquery中,或者我應該使用var pathname = window.location.pathname? – Gordonzo 2011-03-13 07:53:51
這不包括在jQuery中。你應該使用'window.location.href'。這將返回當前頁面的地址。 – Kevin 2011-03-13 08:02:36