使用jQuery在新窗口中打开所有外部链接

使用jQuery在新窗口中打开所有外部链接

问题描述:

这里是jQuery的新功能.我发现了几个网页,它们与我要执行的操作非常接近,但并不完全相同.实际上,我认为以下是应该有效的,但它的意思是:

New to jQuery here. I've found several web pages that come close to what I'm trying to do, but not quite. Actually, I think the following is supposed to actually work, but it's saying:

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

无法识别

(语法错误).有帮助吗?

is not recognized (syntax error). Any help?

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

谢谢.

不需要@符号.除此之外,你真金.

No need for the @ symbol. Other than that, you're golden.

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