Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

今天复习了一下关于getComputedStyle的用法,遇到了小小的挫折。报错前的代码:

<div class="box">
        <div id="box1">
            <input type="text">
            <input type="text">
            <input type="text">
        </div>
    </div>
    <style>
        .box{
            width: 300px;
            height: 200px;
            margin: 20px auto;
            border: 1px solid red;
        }
        #box1{
            width: 100%;
            height: 100px;
            background:blue;
            margin: 5px auto;
        }
    </style>
    <script>
        window.onload=function(){
            var box = document.getElementsByClassName(‘box‘);
            alert(window.getComputedStyle(box,null).height)
        }
    </script>

当然,这只是随便举的例子,然而却遇到了标题上面的报错,纠结了一会后,终于解决了。原来是获取dom元素时,应该通过标签中的id属性去获取,这样仅需要改为

var box = document.getElementById(‘box1‘)就OK啦,是不是很简单。

Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

原文地址:https://www.cnblogs.com/niupeinan/p/11192212.html

时间: 2024-10-22 04:37:49

Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.的相关文章

swagger ui js 错误:Failed to execute &#39;serializeToString&#39; on &#39;XMLSerializer&#39;: parameter 1 is not of type &#39;Node&#39;.

经过排查,引发此错误的原因是,表中有一个字段名称为"NodeName",应该是在前台xml解析时引发冲突所致.我的解决办法是: 修改列名,修改映射. 如下: [Column("NodeName")] public string Name { get; set; } ps:说下我的思路,前台错误处打上断点,循环跳出(或者F8),注意观察出错时的节点名,见下图: 根据此法快速定位到解析错误的表名,然后根据排除法,一个一个注释掉字段,找到出错的字段.剩下的就好办了. sw

fetch 报错 Failed to execute &#39;fetch&#39; on &#39;Window&#39;: Request with GET/HEAD method cannot have body.

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body. 在"窗口"上执行"取"失败:GET / get方法的请求不能有正文. GET requests can't have a request body, you can't make them have one. GET requests only retrieve data,

在vue项目中使用canvas-nest.js,报parameter 1 is not of type &#39;Element&#39;

canvas-nest.js是一款轻量的网页特效,如图: github地址:https://github.com/hustcc/canvas-nest.js 在普通的html项目中,只要将<script src="dist/canvas-nest.js"></script>插入到body标签最下边即可. 在vue项目中,使用时配置 1 import CanvasNest from 'canvas-nest.js'; 2 3 const config = { //

Uncaught SecurityError: Failed to execute &#39;replaceState&#39; on &#39;History&#39;

Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///C:/Users/Administrator/Desktop/%E5%BE%AE%E4%BF%A1/%E4%BA%91%E5%88%9B/index.html' cannot be created in a document with origin 'null'. 在引入jQ

解决Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project autotest_fchtgl: Compilation failure的方法

在碰到maven install 发现报错 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project autotest_fchtgl: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on

Maven错误“Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create ”解决

用maven3新建一个项目时,输入的命令如下: mvn archetype:create 出现错误如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of mojo org.apache.maven.plugins:mav

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 解决办法

Maven install失败 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project autotest_fchtgl: Compilation failure[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE r

Maven创建项目: Failed to execute goal org.apache.maven.plugin( mvn archetype:create)

一.概述: 在使用mvn 命令mvn archetype:create -DgroupId=com.chuanliu.c11 -DartifactId=c11searcher在控制创建maven项目和pom项目时,没有创建成功,错误信息如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli)  on project standalone-p

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of 3: mojo org.apache.maven.plugins:

问题: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli)  on project standalone-pom: Unable to parse configuration of 3:  mojo org.apache.maven.plugins:maven-archetype-plugin:2.4:create for parameter