在我的CSS中,我设置了html的宽度,如下所示:
html {width: 1000px; }
我希望能够使用javascript动态更改此宽度,类似于设置元素的style.width。 window.document节点没有样式属性,我无法在任何地方找到宽度。
DOM中存储的是1000px,我可以动态更改吗?
答案 0 :(得分:2)
你可以随时得到它:
document.documentElement
或:
document.getElementsByTagName('html')[0]
甚至:
document.body.parentElement
所以要获得CSS宽度,只需执行:
document.documentElement.style.width
文档:https://developer.mozilla.org/en-US/docs/Web/API/document.documentElement
返回作为文档根元素的Element(例如,HTML文档的< html>元素)。
答案 1 :(得分:0)
我喜欢这样,亲自
document.body.parentNode.style.width = "1000px";