麻烦帮忙改写JS代码 现在的代码是弹出一个窗口 2秒后自动关闭 我现在要的是在这个基础上添加一个手动关闭

现在的代码如下: 不熟悉JS 麻烦了。 解决了追加分
<SCRIPT LANGUAGE="JavaScript1.2">
adTime=2;//窗口关闭的时间设置
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-400;adDiv.top =documentHeight-100;
setTimeout("showAd()",100);}else closeAd();
}
function closeAd(){
if (ie||w3)
adDiv.display="none";
else
adDiv.visibility ="hide";
}
onload=initAd;
</script>
另外一部分代码 。。。。
<style type="text/css">
<!--
#sponsorAdDiv {position:absolute; height:1; width:1; top:0; left:0;}
-->
</style>
<div id="sponsorAdDiv" style="visibility:hidden;z-index:7; "><img src="123.gif" alt="123" /></div>

function closeWin(){
window.opener=null;//加上这句可以在关闭窗口时不弹出确认提示按钮
window.close();//这句就是关闭窗口的方法
//下面这句话的意思是5秒钟后自动关闭,其中的5000表示5000毫秒
//setTimeout("self.close()",5000);
}
<input type="button" value="关闭" onclick="closeWin()">
保存成网页,点那个按钮,5秒后,网页自动关闭了,而且没有提示.

不好意思,上面那个方法是针对js弹出窗口的,楼主的代码好像是要关闭<div>,可以参照这个例子:(是删除掉<div>而不是隐藏)
<html>
<head>
<script>
function closeDIV(obj)
{
//var obj = document.getElementById("divID"); //也可以直接指定要删除的id
document.body.removeChild(obj);
}
</script>
</head>
<body>
<div style="background-color:red;" onclick="closeDIV(this)">我是一个层,点击关闭我^_^</div>
<body>
</html>
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-01-28
楼主因为只有js代码所以有些东西看不出来,给你个思路好了,在你显示的div里加一个按钮,这个按钮的click事件调用你的closeAd方法
跨浏览器的话,可以考虑用jquery框架,代码如下
$(document).ready(
fucntion()
{
$("#button1").click(function(){$(adDiv).css("display", "none")});
}
);
相似回答