分享使我快乐。
目录
1、 解析很详细,直接看代码。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="button" onclick="on()" value="开灯">
<img id="myphoto" src="关灯.jpg" border="0" >
<input type="button" onclick="off()" value="关灯">
<!--书写开关灯方法-->
<script>
<!-- 开灯方法-->
function on() {
document.getElementById("myphoto").src="开灯.jpg";
}
<!--关灯方法 -->
function off(){
document.getElementById("myphoto").src="关灯.jpg";
}
</script>
<!--定时器开关灯2种
1,无限循环
2,只循环一次-->
<!--<script>
<!– 无限开关灯–>
document.write("开始1秒循环一次无限循环")
flag=0;
setInterval(function (){
if(flag%2==1){
on();
}else {
off();
}
flag++;
},1000)
</script>-->
<!--点击后跳转首页-->
<input type="button" onclick="tz()" value="跳转首页">
<script>
function tz(){
location.href="https://www.csdn.net/"
}
</script>
</body>
</html>
那个定时器开关灯只循环一次,只需把setInterval改为setTimeout就行。
2、结果图
附录:原图2张
3、总结
今天的风儿甚是喧闹