运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <style> #myDIV { height: 250px; width: 400px; padding: 10px; margin: 15px; border: 5px solid red; background-color: lightblue; } </style> <body> <h1>The Element Object</h1> <h2>The clientHeight and clientWidth Properties</h2> <div id="myDIV"> <b>Information about this div:</b><br> Height: 250px<br> Width: 400px<br> Padding: 10px<br> Margin: 15px<br> Border: 5px<br> <p id="demo"></p> </div> <script> const element = document.getElementById("myDIV"); let text = ""; text += "clientHeight: " + element.clientHeight + "px<br>"; text += "offsetHeight: " + element.offsetHeight + "px<br>"; text += "clientWidth: " + element.clientWidth + "px<br>"; text += "offsetWidth: " + element.offsetWidth + "px"; document.getElementById("demo").innerHTML = text; </script> </body> </html>