简体   繁体   English

Jquery:选择一个href链接并使用'each'方法导航

[英]Jquery: Select a href link and navigate with 'each' method

Is it possible using jQuery to select one full link that is in others 'tags'? 是否可以使用jQuery选择其他“标签”中的一个完整链接?

I would like select each href link of each item ( <li> ).. 我想选择每个项目的每个href链接( <li> )..

My idea is to use the method each and then extract the link, for use to navigate then. 我的想法是使用的方法each然后提取链接,用于导航即可。

This is the part of the code of the page: http://pastebin.com/3Vjib4UR 这是该页面代码的一部分: http//pastebin.com/3Vjib4UR

Where in full code of page, there more <li> items in the <ul> tag. 在页面的完整代码中, <ul>标记中还有更多<li>项目。

PS: I would like use the script in an external plugin of firefox (Greasemonkey),and not direct in the page. PS:我想在firefox(Greasemonkey)的外部插件中使用该脚本,而不是直接在页面中。

Thanks in advance. 提前致谢。

Kind regards. 亲切的问候。

Like this? 像这样?

var arr = new Array();

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

Or shorter: 或更短:

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

If you want to get only certain links, just adjust the selector, eg 如果只想获取某些链接,只需调整选择器,例如

$('ul li a')

You really should learn how selectors works in order to use jQuery efficiently. 您确实应该学习选择器的工作原理,以便有效地使用jQuery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM