注册 登录
编程论坛 JavaScript论坛

JS脚本,运行环境chrome油猴,打印变量明明HTMLCollection里有元素,却获取不到?

legendary_br 发布于 2018-08-28 14:33, 2821 次点击
// ==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]

0 回复
1