我有下面這段代碼,指的是通常只有像「#programs」一樣的頁面鏈接的href。但是,我現在需要一些鏈接來引用其他頁面,如「/index.html#programs」。所以我的問題是,如何編輯下面的代碼中的「href」,以便只是數字符號和後面的所有符號?謝謝。刪除字符串href
var lastId, topMenu = $("#main-menu"),
topMenuHeight = topMenu.outerHeight() + 500;
menuItems = topMenu.find('a');
scrollItems = menuItems.map(function() {
content = $(this).attr("href");
if(content){
var checkURL = content.match(/^#([^\/]+)$/i);
if(checkURL){
var item = $($(this).attr("href"));
if (item.length) return item
}
}
});
什麼是這樣做的目的是什麼? – charlietfl