先上图,了解下项目结构
源码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
img{
width: 100px;
height: 180px;
}
.lamp_off{
background: url("img/pic_bulboff.gif");
}
.lamp_on{
background: url("img/pic_bulbon.gif");
}
</style>
<script type="text/javascript">
function fun(){
var lamp=document.getElementById("lamp");
var on_off=document.getElementById("on_off");
var log=document.getElementById("log");
var text=document.createElement("h1");
if(lamp.className=="lamp_off"){
log.appendChild(document.createTextNode(new Date().toString()+"打开