简体   繁体   English

Style.length和Style.width不起作用

[英]Style.length and Style.width are not working

    console.log(document.getElementById("myCanvas").style.length);

I have this code in my program. 我的程序中有这段代码。 It returns 0, despite the length of the canvas being 660. Does anyone know why? 尽管画布的长度为660,但它仍返回0。有人知道为什么吗?

You can get the width and height through this. 您可以通过它获得宽度和高度。

var canvas = document.getElementById("myCanvas");
var width = canvas.width;
var height = canvas.height;

In CSS there is no length attribute, there is just height or width. 在CSS中,没有长度属性,只有高度或宽度。 You can use this: 您可以使用此:

console.log(document.getElementById("myCanvas").style.height);
console.log(document.getElementById("myCanvas").style.width);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM