JS脚本,运行环境chrome油猴,打印变量明明HTMLCollection里有元素,却获取不到?
// ==UserScript==// @name 微博搜索页净化
// @namespace http://
// @version 0.1
// @description 净化微博搜索页面,去除热门和推广。
// @author chuan
// @match http://s.*
// @grant none
// ==/UserScript==
(function() {
var rightEle = document.getElementById("pl_weibo_directright");
rightEle.style.display = "none";
var hotband = document.getElementById("pl_weibo_hotband");
hotband.style.display = "none";
var nodes = document.getElementById("pl_weibo_direct").children;
console.log(nodes);
console.log(nodes==null);
console.log(nodes.length);
console.log(nodes[0]);
var elements = document.getElementById("pl_weibo_direct").firstElementChild.children;
console.log(elements);
console.log(elements.length);
for(var i = elements.length - 4 ; i > -1 ; i--){
elements[i].style.display = "none";
}
})();
[local]1[/local]
[local]2[/local]