var graph =""; function clickitem() { var items = document.getElementsByName("load"); var i; for (i = 0; i < items.length; i++) { if(items[i].text == "加载更多") { items[i].click(); break; } else if(items[i].text == "显示子话题") { var dataparent = items[i].getAttribute("data-parent"); console.log(dataparent); if(graph.indexOf(dataparent) == -1) { graph = graph + "," + dataparent; console.log(graph); items[i].click(); break; } } } }