源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <style> #myDIV { height: 250px; width: 400px; padding: 10px; margin: 15px; border-left: 10px solid red; background-color: lightblue; direction: rtl; overflow: scroll; } </style> </head> <body> <p>点击按钮,获取左侧边框的宽度。</p> <button onclick="myFunction()">点我</button> <div id="myDIV"> div 元素的文本方向是从右到左。<br> 并且它有一个滚动条! <p id="demo"></p> </div> <script> function myFunction() { var left = document.getElementById("myDIV").clientLeft; document.getElementById("demo").innerHTML = "左侧边框宽度: " + left + "px"; } </script> </body> </html>
运行结果: