使用jQuery在新窗口中打开所有外部链接 [英] Using jQuery to open all external links in a new window
本文介绍了使用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://']")...
这篇关于使用jQuery在新窗口中打开所有外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文