Jquery:选择一个 href 链接并使用“each”进行导航方法

发布于 2024-10-06 20:52:49 字数 461 浏览 0 评论 0原文

是否可以使用 jQuery 选择其他“标签”中的完整链接?

我想选择每个项目的每个 href 链接 (

  • )。
  • 我的想法是使用方法 each 然后提取链接,用于导航然后。

    这是页面代码的一部分: http://pastebin.com/3Vjib4UR

    完整代码页面中,

      标记中有更多
    • 项。

    PS:我想在 firefox (Greasemonkey) 的外部插件中使用该脚本,而不是直接在页面中使用。

    提前致谢。

    亲切的问候。

    Is it possible using jQuery to select one full link that is in others 'tags'?

    I would like select each href link of each item (<li>)..

    My idea is to use the method each and then extract the link, for use to navigate then.

    This is the part of the code of the page: http://pastebin.com/3Vjib4UR

    Where in full code of page, there more <li> items in the <ul> tag.

    P.S: I would like use the script in an external plugin of firefox (Greasemonkey),and not direct in the page.

    Thanks in advance.

    Kind regards.

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(2

    鱼窥荷 2024-10-13 20:52:49

    或者更短:

    var links = $('a').map(function(){ return this.href;}).get();
    

    如果您只想获取某些链接,只需调整选择器,例如

    $('ul li a')
    

    您确实应该了解如何 < em>选择器 的作用是为了有效地使用 jQuery。

    Or shorter:

    var links = $('a').map(function(){ return this.href;}).get();
    

    If you want to get only certain links, just adjust the selector, e.g.

    $('ul li a')
    

    You really should learn how selectors works in order to use jQuery efficiently.

    寂寞花火° 2024-10-13 20:52:49

    像这样?

    var arr = new Array();
    
    $("a").each(function(){ arr.push($(this).attr("href"); });
    

    Like this?

    var arr = new Array();
    
    $("a").each(function(){ arr.push($(this).attr("href"); });
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文