1.夜間模式的開啓與關閉css
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>夜間模式</title> <script> function mySwitch() { var oBody=document.getElementById("myBody"); var oOnoff=document.getElementById("myOnOff"); if (oOnoff.src.match("bulbon")){ oOnoff.src="http://www.runoob.com/images/pic_bulboff.gif"; oBody.style.background="black"; oBody.style.color="white"; }else { oOnoff.src="http://www.runoob.com/images/pic_bulbon.gif"; oBody.style.background="white"; oBody.style.color="black"; } } </script> </head> <body id="myBody"> <img id="myOnOff" onclick="mySwitch()" src="http://www.runoob.com/images/pic_bulbon.gif" width="40px"> <script> document.write(Date()) </script> </body> </html>
2.父模板的製做html
htmlweb
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>夜間模式</title>
<link rel="stylesheet" type="text/css" href="../static/css/wang.css">
<script>
function mySwitch() {
var oBody=document.getElementById("myBody");
var oOnoff=document.getElementById("myOnOff");
if (oOnoff.src.match("bulbon")){
oOnoff.src="http://www.runoob.com/images/pic_bulboff.gif";
oBody.style.background="black";
oBody.style.color="white";
}else {
oOnoff.src="http://www.runoob.com/images/pic_bulbon.gif";
oBody.style.background="white";
oBody.style.color="black";
}
}
</script>
</head>
<script>
document.write(Date())
</script>
<nav>
<a href="http://www.gzcc.cn/">首頁</a>
<input type="text" ></input>
<button type="submit">搜索</button>
<a href="">登陸</a>
<a href="">註冊</a>
</nav>
<p align="right"><img id="myOnOff" onclick="mySwitch()" src="http://www.runoob.com/images/pic_bulbon.gif" width="40px"></p>
<body id="myBody">
<div class="recommond">
<div class="img">
<a href="http://www.jianshu.com/"><img src="http://cdn2.jianshu.io/assets/web/logo-58fd04f6f0de908401aa561cda6a0688.png"></a>
<div class="desc"><a href="http://www.jianshu.com/">簡書</a></div>
</div>
</div>
</body>
</html>
css函數
img { width: 180px; } div.img{ border:1px solid #cccccc; float: left; margin: 5px; width:180px; height: 200px; } div.img img{ width:100%; height:100%; } div.desc{ text-align: center; padding: 5px; } div.img:hover{ border:1px solid #000000; }
js網站
function mySwitch() { var obody = document.getElementById("mybody"); var oOnoff = document.getElementById("myOnOff"); if(oOnoff.src.match("bulbon")){ oOnoff.src="http://www.runoob.com/images/pic_bulboff.gif"; obody.style.background="black"; obody.style.color="white"; }else{ oOnoff.src="http://www.runoob.com/images/pic_bulbon.gif"; obody.style.background="white"; obody.style.color="black"; } }