标题 灯泡的点击
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<img id="calss" src="img/p1.jpg" height="200" width="300" /><br />
<div id="liss" height="100" width="100"></div>
<button id="push" onclick="reg()">按钮</button>
<script type="text/javascript">
var time=new Date();
var img =["img/p1.jpg","img/p2.jpg"];
var i=0;
function reg(){
document.getElementById("calss").src = img[i];
if(i == 0){
i = 1;
var a = time.getFullYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"号"+
time.getHours()+"时"+time.getMinutes()+"分"+time.getSeconds()+"秒";
document.getElementById("push").innerHTML="开";
document.getElementById("liss").innerHTML = a +":灯灭啦";
}else{
i=0;
var a = time.getFullYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"号"+
time.getHours()+"时"+time.getMinutes()+"分"+time.getSeconds()+"秒";
document.getElementById("push").innerHTML="关";
document.getElementById("liss").innerHTML = a +":灯亮啦";
}
}
</script>
</body>
</html>
标题 代码按钮点击实现效果