87,918
社区成员
发帖
与我相关
我的任务
分享
<!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=gb2312" />
<title>无标题文档</title>
<style type="text/css">
#div1{
border:1px solid #333;
position:absolute;
left:200px;
top:200px;
background:green;
width:200px;
height:200px;
}
#div2{
border:1px solid #333;
position:absolute;
left:150px;
top:150px;
background:red;
width:200px;
height:200px;
}
</style>
<script language="javascript">
var fou=null;
var t=0;
var c=null;
function run()
{
$("div1").style.zIndex=1;
fou=$("div1");
clearTimeout(c);
c=setTimeout("s()",1000);
}
function click(e)
{
if(t==10)t=0;
if(t<5)
{
if(e.id=="div1")
{
$("div1").style.zIndex=2;
$("div2").style.zIndex=1;
}
else
{
$("div1").style.zIndex=1;
$("div2").style.zIndex=2;
}
t=0;
fou=e;
clearTimeout(c);
c=setTimeout("s()",1000);
}
}
function s()
{
t++;
$("show").innerHTML=t;
if(t==10)
document.body.removeChild(fou);
else
{
clearTimeout(c);
c=setTimeout("s()",1000);
}
}
function $(_id)
{
if(document.getElementById(_id))
{ return document.getElementById(_id);}
else{ var obj=document.createElement("div");obj.id=_id; obj.innerHTML=_id; obj.onclick=function(){click(obj);};document.body.appendChild(obj);return document.getElementById(_id); }
}
</script>
</head>
<body>
<input name="" type="button" value="显示层" onclick="run()" />
<div id="show"></div>
</body>
</html>
<HTML>
<head>
<title>sample</title>
<script language="JavaScript">
var t;
function show(div1,div2){
if(t)clearTimeout(t);
document.getElementById(div1).style.display="block";
document.getElementById(div2).style.display="none";
t=setTimeout(clear,10000);
}
function clear(){
document.getElementById("div1").style.display="none";
document.getElementById("div2").style.display="none";
}
</script>
</head>
<body>
<input type=button id=btn1 onclick="show('div1','div2');" value="show">
<div id=div1 style="background:red;position:absolute;top:100px;left:100px;width:100px;height:100px;display:none;" onclick="show('div2','div1');"></div>
<div id=div2 style="background:green;position:absolute;top:100px;left:100px;width:100px;height:100px;display:none;" onclick="show('div1','div2');"></div>
</body>
</html>