JS自学第五弹

(1)JS修改HTML标签的属性:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js-dom-html</title>
</head>
<body>
  <input type="text" id="input">
</body>
<script>
  // JS将input标签的type属性修改成为button
  document.getElementById('input').type = "button";
</script>
</html>

(2) JS修改标签的样式:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js-dom-css</title>
  <style>
    #box{
      height:100px;
      width: 100px;
      background-color: #000;
    }
  </style>
</head>
<body>
  <div id="box"></div>
</body>
<script>
  // JS 给 div 的样式增加个 边框的样式
  document.getElementById('box').style.border = "1px solid #f00";
</script>
</html>

猜你喜欢

转载自blog.csdn.net/qq_35134503/article/details/84391339