【问题标题】:Using jQuery to open all external links in a new window使用 jQuery 在新窗口中打开所有外部链接
【发布时间】:2009-12-09 03:14:41
【问题描述】:

这里是 jQuery 新手。我发现有几个网页接近我想要做的事情,但不完全是。实际上,我认为以下是 supposed 实际工作,但它是说:

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

无法识别(语法错误)。有什么帮助吗?

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

谢谢。

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

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

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

    【讨论】:

    • 只是为了扩展这一点 - 从 jQuery 1.2.6 和 1.3.x 开始,@ 已被弃用。
    猜你喜欢
    • 1970-01-01
    • 2016-01-22
    • 2013-06-10
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多