<!DOCTYPE HTML><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DIV變色練習</title> <style type="text/css"> div { margin:0 auto; ? ?width:600px; height:200px; background-color:yellow; } p { text-align:center; } </style></head><body> <div id="div-one" ></div> <p> <button type="button" onclick="objDiv()">點我</button> </p> <script> function objDiv(){ a=document.getElementById("div-one"); a.style.background="green" } </script></body></html>
怎么才能通過點按鈕來回切換DIV的背景色呢?
0_夢醒無痕_0
2016-03-09 22:56:21