Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách đặt tất cả thuộc tính viền dưới trong một khai báo trong JavaScript DOM?

Sử dụng shorthand borderBottom để đặt width, style, color cho viền dưới cùng lúc.

Ví dụ

<!DOCTYPE html>
<html>
  <head>
    <style>
      #box { border: 2px dashed blue; width: 120px; height: 120px; }
    </style>
  </head>
  <body>
    <button onclick="display()">Đặt viền dưới</button>
    <div id="box"><p>Demo Text</p><p>Demo Text</p></div>
    <script>
      function display() {
        document.getElementById("box").style.borderBottom = "thin dashed #000000";
      }
    </script>
  </body>
</html>