轮播图(手动)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>点亮张家</title>
<style type="text/css">
#next,#last{
width:80px;
height:40px;
}
</style>
</head>
<body>
<img src="001.jpg" id="Myimg" />
<button id="next">Next</button>
<button id="last">Last</button>
<script type="text/javascript">
var image=document.getElementById('Myimg');
var next=document.getElementById('next');
var last=document.getElementById('last');
var nowIndex=1;
var count=3;
next.onclick=function(){
if(nowIndex+1>3){
nowIndex=1;
}
else
{
nowIndex++;
}
image.src="00"+nowIndex+".jpg";
}
last.onclick=function(){
if(nowIndex-1<1){
nowIndex=3;
}
else{
nowIndex--;
}
image.src="00"+nowIndex+".jpg";
}
</script>
</body>
</html>
猜数字小游戏
先猜个1到10之间的吧
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>猜数字1到10之间的数字</title>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">
var name=Math.floor(Math.random()*10+1);
do{
var guess=parseInt(prompt("请输入1到10之间你猜整的数:",""));
if(guess==name){
alert("恭喜!猜对了!!");
break;
}
else if(guess>name){
alert("你猜的数有点大");
go_on=confirm("是否继续游戏?");
}
else{
alert("你猜的数有点小");
go_on=confirm("是否继续游戏?");
}
}while(go_on);
alert("谢谢参与游戏");
</script>
</body>
</html>
自动轮播图(自动)
定时器:setInterval:按照指定周期(以毫秒计)来调用函数或计算表达式,方法会不停的调用函数,直到clearInterval被调用 用setInterval写了个简单的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
</style>
</head>
<body>
<img src="001.jpg" id="myimg" />
<script type="text/javascript">
var img=document.getElementById('myimg');
var Index=1;
var count=3;
var mytime=setInterval(clock,300);
function clock(){
if(Index+1>count)
Index=1;
else
Index++;
img.src="00"+Index+".jpg";
}
</script>
</body>
</html>
运行的时钟
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>运行的时钟</title>
<style type="text/css">
</style>
</head>
<body onload="clock()">
<span id="yeartime"></span>
<script type="text/javascript">
function clock(){
var date=new Date();
var year=date.getFullYear();
var month=date.getMonth()+1;
var day=date.getDate();
var hour=date.getHours();
var minute=date.getMinutes();
var second=date.getSeconds();
if(hour<10)
hour='0'+hour;
if(minute<10)
minute='0'+minute;
if(second<10)
second='0'+second;
document.getElementById('yeartime').innerHTML= year+"年"+month+"月"+
day+"日"+hour+":"+minute+":"+second;
var mytime=setTimeout("clock()",1000);
}
</script>
</body>
</html>
|