亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JS控制DIY樣式學習總結

Original 2018-11-25 19:42:08 319
abstract:<!DOCTYPE html> <html> <head>   <meta charset="UTF-8">   <meta name="viewport" content="width=device-width,&
<!DOCTYPE html>
<html>
<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>Document</title>
  <style media="screen">
    .center{padding-top: 20px;text-align: center;}
    input{width: 50px;height: 25px;background: rgb(0,0,0,0);}
    #box{width: 100px;height: 100px;background:#2E6CD6;margin: 0 auto;margin-top: 50px;}
  </style>
</head>
<body>
<div>
  <input type="button" value="變寬" onclick="Owidth()">  <!-- 當用戶點擊按鈕觸發(fā)事件函數(shù) -->
  <input type="button" value="變高" onclick="Oheight()">
  <input type="button" value="變色" onclick="Obgcolor()">
  <input type="button" value="變圓" onclick="Oradius()">
  <input type="button" value="隱身" onclick="Onone()">
  <input type="button" value="顯示" onclick="Oblock()">
  <input type="button" value="重置" onclick="Orest()">
  <div id="box"></div>
</div>
<script type="text/javascript">

  var box;
  window.onload = function (){  //window.onload 事件加載完后觸發(fā),這應該算是為全局函數(shù)了吧!
    box = document.getElementById('box');//獲取頁面中的 DOM元素
  }
      function Owidth(){  //聲明一個函數(shù)名  Owidth ,然后通過全局函數(shù)獲取到的DOM元素修改其CSS樣式
        box.style.width = "400px"//請教下老師,“400px”后面要加分號嗎?加到“”里面結果效果出不來。
      }
      function Oheight(){
        box.style.height = "400px"
      }
      function Obgcolor(){
        box.style.background = "#AD05FF"
      }
      function Oradius(){
        box.style.borderRadius = "50%"
      }
      function Onone(){
        box.style.display = "none"
      }
      function Oblock(){
        box.style.display = "block"
      }
      function Orest(){//重置
        box.style.width = "100px"
        box.style.height = "100px"
        box.style.background = "#2E6CD6"
        box.style.borderRadius = "0"
      }
</script>
</body>
</html>

老師看下我注釋中的理解是否有誤,請您指點,辛苦了您!

Correcting teacher:天蓬老師Correction time:2018-11-25 20:21:43
Teacher's summary:如果用window.onload , 那么js代碼可以放到head中,不必放到body前了,注釋還算清楚,畢竟初學,離規(guī)范還有差距. 還有,注釋盡可能寫到語句上面,不要寫到右邊,便于進行調(diào)試

Release Notes

Popular Entries