如何使用 JavaScript 設定元素邊框的寬度?
若要使用 JavaScript 設定元素邊框的寬度,請使用 borderWidth 屬性。使用此屬性設定寬度。
可以嘗試執行以下程式碼來了解如何設定元素邊框的寬度 −
示例
即時演示<!DOCTYPE html> <html> <head> <style> #box { border: thick solid gray; width: 300px; height: 200px } </style> </head> <body> <div id = "box">Demo Text</div> <br> <br> <button type = "button" onclick = "display()">Change border width</button> <script> function display() { document.getElementById("box").style.borderWidth = "thin"; } </script> </body> </html>
廣告