我正在建立所有頁面使用Ajax加載的Wordpress網站。我使用Chris Coyer創建的腳本,可以找到here。下面的代碼將爲網站上的所有鏈接添加特定的標籤。 Wordpress將嘗試使用Ajax從這些鏈接加載內容。問題在於,這些屬性正在應用到PDF和ZIP文件的鏈接上,這些文件將被下載,而不是加載到頁面中。該腳本將特定的attr應用於網站上的所有鏈接。如何排除PDF和ZIP文件?
如何從獲取這些屬性中排除特定的文件格式?我已經嘗試過這樣的$internalLinks = $("a[href^='"+siteURL+"']:not([href$=/*.pdf])")
,但那對我不起作用。難道我做錯了什麼?
下面是添加屬性的原始代碼的一部分。完整的代碼可以在JSFiddle page找到。謝謝!
var $mainContent = $("#main-content"),
siteURL = "http://" + top.location.host.toString(),
$el = $("a");
function hashizeLinks() {
$("a[href^='" + siteURL + "']").each(function() {
$el = $(this);
// Hack for IE, which seemed to apply the hash tag to the link weird
if ($.browser.msie) {
$el.attr("href", "#/" + this.pathname).attr("rel", "internal");
} else {
$el.attr("href", "#" + this.pathname).attr("rel", "internal");
}
});
};
我新我缺少的東西。這正是我正在尋找的。感謝gilly3! – Klikerko 2012-03-13 06:03:35