如果.clientHeight为null且没有元素,则回退

时间:2013-08-26 10:31:21

标签: jquery canvas

我在网站上有2个画布元素。 javascript检查周围div的高度和宽度,并设置画布的高度和宽度。

var height = parseInt(document.getElementById("canvaselement").clientHeight); var height2 = parseInt(document.getElementById("canvaselement2").clientHeight);

问题是,如果两个画布元素中的一个不存在于子页面上,则脚本将停止工作。

控制台为我提供了**Uncaught TypeError: Cannot read property 'clientHeight' of null **

我尝试了类似

的东西
if (height = null) {
    console.log("height null");
} 

如果没有画布元素,我如何获得后备?有什么想法或建议吗?

问候 denym

0 个答案:

没有答案