【问题标题】:Change the opacity of all elements in webpage by running chrome console通过运行 chrome 控制台更改网页中所有元素的不透明度
【发布时间】:2021-09-28 20:09:31
【问题描述】:

我已经尝试过了,但它返回错误(未捕获的类型错误:无法设置未定义的属性“不透明度”)

console.dir(document.getElementsByTagName("*").style.opacity="0.5");

【问题讨论】:

    标签: google-chrome console element opacity


    【解决方案1】:

    document.getElementsByTagName("*") 返回一个元素数组。您不能使用elements.style 同时访问所有这些元素的样式。

    您可以像这样设置第一个元素(应该是根元素)的样式:

    document.getElementsByTagName("*")[0].style.opacity = 0.5
    

    这将影响根元素及其所有子元素。

    【讨论】:

      猜你喜欢
      • 2014-12-19
      • 2012-03-28
      • 1970-01-01
      • 2011-01-22
      • 2011-07-30
      • 1970-01-01
      • 1970-01-01
      • 2015-02-22
      相关资源
      最近更新 更多