function test() { //輸出html function out_innerHTML(objs) { for (var i = 0; i < objs.length; i++) { //console.log(t[i]); //console.log(t[i].getElementsByClassName("icon").length); //console.log(t[i].innerHTML.indexOf("天貓")); //console.log(t[i].innerHTML); return objs[i].innerHTML.indexOf("天貓"); } } var t = document.getElementById("mainsrp-itemlist").getElementsByClassName("item"); //console.log(t); for (var i = 0; i < t.length; i++) { var icons_list = t[i].getElementsByClassName("icons"); //得到icon元素的集合 if (out_innerHTML(icons_list) > 0) { t[i].style.backgroundColor = "#000"; // 駝峯命名法 t[i].style.opacity = 1 / 100; //t[i].style.color ="#000"; } else { t[i].style.backgroundColor = "aqua"; // 駝峯命名法 } //console.log(t1); } } var i = 0; var int = self.setInterval(function () { test(); console.log(1); }, 3000);