[英]jquery attr('href') not working
更新,問題已解決。 問題出在我試圖更改HREF(實際上是將其變回)之后調用的函數。
使用jQuery,我試圖根據URL中包含的哈希值更改一系列鏈接的HREF屬性,但是該屬性只是沒有變化,而是被更改為空字符串。
有人可以在這里看到我在做什么錯嗎? 為什么不起作用?
http://fwy.pagodabox.com/categories/sculptures/#grid
有問題的鏈接是
所有展覽裝置物件印刷品雕塑
在二級導航中
function navHash($navlinks, hashtxt) {
// loop through specified links
$navlinks.each(function(){
var $me = $j(this),
myhref,
index;
// Does this link have an href… if not move on
if( typeof $me.attr('href') === "undefined" )
return false;
myhref = $me.attr('href');
index = myhref.indexOf('#');
// if my href doesn't have the specified hash text, add it, else remove it
if(myhref.indexOf(hashtxt) === -1) {
$me.attr("href", hashtxt);
} else {
$me.attr("href", myhref.substring(0, index));
}
});
}
$j(document).ready(function($){
var $navlinks = $j('.sub-nav li:not(.views) a');
if(window.location.hash == '#grid') {
navHash($navlinks, '#grid');
$('.views .ic-grid').click();
}
// so on...
謝謝!!!
如果您在此處返回false
,則將停止循環。
if(typeof $me.attr('href') === "undefined")
return false;
返回true
繼續循環。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.