如何在 JavaScript 中使用一个声明设置 border 宽度、样式和颜色?


要在单个声明中设置边框宽度、样式和颜色,请在 JavaScript 中使用 border 属性。

示例

你可以尝试运行以下代码,了解如何在 JavaScript 中设置边框−

在线演示

<!DOCTYPE html>
<html>
   <body>
      <button onclick="display()">Set border</button>
      <div id="box">
         <p>Demo Text</p>
         <p>Demo Text</p>
      </div>
      <script>
         function display() {
            document.getElementById("box").style.border = "thick dashed #000000";
         }
      </script>
   </body>
</html>

更新于: 2020 年 6 月 23 日

882 次浏览

开启你的 职业生涯

完成课程获得认证

马上开始
广告
© . All rights reserved.