zoukankan      html  css  js  c++  java
  • 样式操作案例1

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <style>
        .cls {
          width: 100px;
          height: 100px;
          background-color: red;
        }
      </style>
    </head>
    <body>
      <input type="button" id="btn" value=" 点我 "> <br>
      <div id="box"></div>  
    
      <script src="common.js"></script>
      <script>
        // 操作样式的时候,使用类样式 使用style?
        // 当设置多个样式属性的时候使用类样式方便
        // 当设置样式属性比较少的时候使用style比较方便
        // 
        // 
        // 
        // 1 类样式
        // my$('btn').onclick = function () {
        //   my$('box').className = 'cls';
        // }
        // 2 使用style
        my$('btn').onclick = function () {
          // 当设置宽度和高度的时候必须带单位,如果不带单位,有错误
          var box = my$('box');
          box.style.width = '200px';
          box.style.height = '200px';
          box.style.backgroundColor = 'red';
        }
    
    
      </script>
    </body>
    </html>

    common里面的代码

    function my$(id) {
      return document.getElementById(id);
    }
  • 相关阅读:
    HDU1864--01背包
    HDU4508--完全背包
    HDU5410--01背包+完全背包
    HDU1284--完全背包
    HDU1248--完全背包
    HDU2191--多重背包(二进制分解+01背包)
    HDU2186--水
    PAT乙级--1003
    51Nod--1006 lcs
    51Nod--1008
  • 原文地址:https://www.cnblogs.com/jiumen/p/11405011.html
Copyright © 2011-2022 走看看