java脚本如何循环遍历href的列表 [英] java script How to loop though a list of href's

查看:74
本文介绍了java脚本如何循环遍历href的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接的分支,一个接一个,另一个在它们之间. 我想遍历每个链接并调用其click()事件 最好的方法是什么?

i have branch of links placed one after the other with
between them i want to loop though each link and invoke its click() event what is the best way to do this?

<div id="playlistContainer" >
<a href="javascript:void(0);" onclick="loadNewVideo('xxxx1','0');">Blah 1</a><br>
<a href="javascript:void(0);" onclick="loadNewVideo('xxxxx3','0');">Blah 1</a><br>
<a href="javascript:void(0);" onclick="loadNewVideo('xxxxx4','0');">TBlah 2</a><br>
<a href="javascript:void(0);" onclick="loadNewVideo('xxxxx5','0');">Blah 3</a><br>
<a href="javascript:void(0);" onclick="loadNewVideo('xxxxx6','0');">Blah 4</a><br>
</div>

因此,当我知道第一个链接对象时,如何知道列表中的下一个链接(href对象)?

so when i know the first link object how can i know the next link (href object ) which is next in the list?

更新: 感谢您回答有关循环的问题,但是我的最后一个问题是,如果我将第一个链接作为函数中的对象,我如何知道下一个链接是什么?

UPDATE: Thank for answering about the loop , but my last question is , if i have the first link as object in function , how can i know what is the next link ?

推荐答案

尝试一下:

var as = document.getElementsByTagName("a");
for (var i=0; i<as.length; i++) {
  // Call the "onclick" handler for each "a" element.
  as[i].onclick();
}

这篇关于java脚本如何循环遍历href的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆