2011-09-21 79 views

回答

14
$("a[target='_blank']").attr('target', 'sometarget');

你的意思是這樣的嗎?

0

嘗試

 $("a[target=_blank]").each(function() { 
      var href = $(this).attr("href"); // retrive href foreach a 
      $(this).attr("href", "something_you_want"); // replace href attribute with wich u want 
      // etc 
     }); 

讓我知道你想要什麼,以獲得更多幫助

0

如果你專門找它具有空值href值然後執行以下操作

$('a[href=""]').each(function() { 
    $(a).attr('href', 'theNewUrl'); 
}); 

這將只捕獲具有空href屬性的錨標籤。這雖然不會對錨缺少href標記

<a href="">Link 1</a> <!-- Works --> 
<a>Link 2</a> <!-- Won't work --> 

如果您需要匹配後者然後執行以下操作

$('a').each(function() { 
    var href = $(this).attr('href') || ''; 
    if (href === '') { 
    $(this).attr('href', 'theNewUrl'); 
    } 
});