[英]Compatibility issue with <!DOCTYPE html> and .clientHeight JavaScript
I am experiencing issues with when setting the height of one DIV based on .clientHeight of another DIV. 我在基于另一个DIV的.clientHeight设置一个DIV的高度时遇到问题。
Sample of my JS below: 我的JS示例如下:
<script>
var height1 = document.getElementById("DIV1").clientHeight;
document.getElementById("DIV2").style.height = height1;
</script>
The weird thing is that when I remove the doctype declaration from the top of the page, the javascript performs the operation correctly (obviously I dont want to remove the doctype from the page...) 奇怪的是,当我从页面顶部删除doctype声明时,javascript正确执行了该操作(显然,我不想从页面上删除doctype ...)
Solution: 解:
<script>
var height1 = document.getElementById("DIV1").clientHeight;
document.getElementById("DIV2").style.height = height1 + "px";
</script>
The style.height requires the length not the numeric value. style.height需要长度而不是数字值。
Hope this helps someone else... 希望这可以帮助其他人...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.