2009-12-09 61 views
5

這裏是jQuery的新手。我發現幾個網頁接近我想要做的,但不完全。其實,我覺得有以下爲應該實際工作,但它在說:使用jQuery在新窗口中打開所有外部鏈接

[@href^="http://"] 

無法識別(語法錯誤)。任何幫助?

$(document).ready(function() { 
    $('a[@href^="http://"]').filter(function() { 
     return this.hostname && this.hostname !== location.hostname; 
    }).attr('target', '_blank'); 
}); 

謝謝。

回答

9

不需要@符號。除此之外,你是金。

$("a[href^='http://']")... 
+4

只是爲了擴大這一點 - 從jQuery 1.2.6和1.3.x開始棄用了@。 –

相關問題