简体   繁体   English

如何触发childNode点击事件

[英]how to trigger childNode click event

I have a parent DIV and it has many child divs. 我有一个家长DIV,并且有很多孩子div。 Those child divs are clickable, and I am trying to trigger click event on each divs in order with setInterval(funcLoop, 5000) 这些子div是可点击的,我试图按setInterval(funcLoop,5000)的顺序触发每个div上的点击事件

....
setInterval(funcLoop, 5000);
....
....
function funcLoop()
{
    var c = document.getElementById("divParent").childNodes;
    c[index].click();
    index++;
    if (index == document.getElementById("divParent").childNodes.length)
        index = 0;
}

But, I am getting the error below 但是,我得到下面的错误

Uncaught TypeError: c[index].click is not a function

can anybody tell me what I should do to fix this? 谁能告诉我该如何解决?

childNodes also includes text nodes and comments, which does not have click handlers. childNodes还包括文本节点和注释,其中没有click处理程序。

Replace childNodes with children , or do 更换childNodeschildren ,或做

setInterval(funcLoop, 5000);
....
....

function funcLoop() {
    var c = document.getElementById("divParent").children;

    for (var i=c.length; i--;) {
        c[i].click();
    }
}

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

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