js让窗口显示几秒钟然后消失

我想在页面上做一个每天第一次登录给奖励的效果,判断的数据可以从后台取到,该如何做这个效果呢?我的想法是写一个隐藏的div,判断后让它显示,这些我会做,但是如何设定时间让它自动消失呢?

<!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>
</head>

<body>
<div id="a" style="width:200px; height:200px; background:#C03" onclick="aa();">点击此处后五秒消失</div>
<script>
function aa(){
setTimeout("hide()",5000) // 这个是主要参数,设置消失的时间
}
function hide(){
document.getElementById('a').style.display='none'; //这个是操作DIV消失的命令
}
</script>
</body>
</html>
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-07-08
你会做DIV好办,你参考下面的js嵌入到代码中就行的。
<!--此特效代码区域加入body标签之间-->
<style type="text/css">
<!--
#sponsorAdDiv {position:absolute; height:1; width:1; top:0; left:0;}
-->
</style>
<SCRIPT LANGUAGE="JavaScript1.2">
adTime=8;

chanceAd=1;
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
adCount=0;
function initAd(){
if(!ns && !ie && !w3) return;
if(ie) adDiv=eval('document.all.sponsorAdDiv.style');
else if(ns) adDiv=eval('document.layers["sponsorAdDiv"]');
else if(w3) adDiv=eval('document.getElementById("sponsorAdDiv").style');
randAd=Math.ceil(Math.random()*chanceAd);
if (ie||w3)
adDiv.visibility="visible";
else
adDiv.visibility ="show";
if(randAd==1) showAd();
}
function showAd(){
if(adCount<adTime*10){adCount+=1;
if (ie){documentWidth =document.body.offsetWidth/2+document.body.scrollLeft-20;
documentHeight =document.body.offsetHeight/2+document.body.scrollTop-20;}
else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
documentHeight=window.innerHeight/2+window.pageYOffset-20;}
else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
documentHeight=self.innerHeight/2+window.pageYOffset-20;}
adDiv.left=documentWidth-200;adDiv.top =documentHeight-200;
setTimeout("showAd()",100);}else closeAd();
}
function closeAd(){
if (ie||w3)
adDiv.display="none";
else
adDiv.visibility ="hide";
}
onload=initAd;
</script>
<div id="sponsorAdDiv" style="visibility:hidden">
本例显示的时间为8秒,祝你成功!
第2个回答  2011-07-08
var width=510; var height=220; var left = ( screen.width - width ) / 2; var top = ( screen.height - height ) / 2; window.open(
第3个回答  2011-07-08
jquery 窗口有这个功能 你可以去查询相关的资料看看
相似回答