duanlinghe8417 2016-03-19 09:53
浏览 58
已采纳

自动触发列表href链接逐一

I have list of href with a function called in it,how to auto trigger href link function with parameter i used and pass to JavaScript. I have included my code below.

<html>
<head>
 //Add jwplayer script
</head>
<body>
<div id='VideoPlayer'>Loading the player ...</div>
<ul id="myList">
  <li><a href="#" onclick="show_alert('sample video1','image1')">Test</a>
  <li><a href="#" onclick="show_alert('sample video2','image2')">Test1</a>
</ul>
<script type="text/javascript">
function show_alert(my_string,s)
{

var playerInstance = jwplayer('VideoPlayer');
playerInstance.setup({
file: my_string,
image: s,
title: 'My Cool Video',
primary: 'html5',
width: 640,
height: 480
});
}
[].forEach.bind(document.querySelectorAll("#myList li a"),function(itm){
itm.click();
})(); </script></body></html>
  • 写回答

2条回答 默认 最新

  • doushi2047 2016-03-19 10:43
    关注

    It might be as simple as this

    var anchors = document.querySelectorAll("#myList li a");
    
    for(var i = 0; i < anchors .length; i++) {
      (function(i) {
        anchors [i].click();
      })(i);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料