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

Cách đặt kiểu viền trên (border-top-style) với JavaScript?

Sử dụng borderTopStyle để đặt kiểu đường viền cho cạnh trên (solid, dashed, dotted...).

Ví dụ

<!DOCTYPE html>
<html>
  <head>
    <style>
      #box { border: thick solid gray; width: 300px; height: 300px; }
    </style>
  </head>
  <body>
    <div id="box">Demo Text</div>
    <br><br>
    <button type="button" onclick="display()">Thay đổi kiểu viền trên</button>
    <script>
      function display() {
        document.getElementById("box").style.borderTopStyle = "dashed";
      }
    </script>
  </body>
</html>