Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่าคุณสมบัติเส้นขอบด้านบนทั้งหมดในการประกาศเดียวด้วย JavaScript


หากต้องการตั้งค่าคุณสมบัติเส้นขอบด้านบนทั้งหมดในการประกาศเดียว ให้ใช้คุณสมบัติ borderTop ด้วยคุณสมบัตินี้ คุณสามารถตั้งค่า border-top-width, border-top-style, และ border-top-color ได้

ตัวอย่าง

คุณสามารถลองรันโค้ดต่อไปนี้เพื่อเรียนรู้วิธีทำงานกับคุณสมบัติ border-top ใน JavaScript −

<!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 top border</button>       <script>          function display() {             document.getElementById("box").style.borderTop = "thick solid #000000";          }       </script>    </body> </html>