Este artigo descreve o método do JS para bloquear automaticamente a camada DIV em 5 segundos. Compartilhe para sua referência. O método de implementação específico é o seguinte:
Copie o código da seguinte forma: <html>
<head>
<Title> JS implementa o bloqueio automático da camada div em 5 segundos </title>
<style type = "text/css">
<!-
#SponsorAddiv {Posição: Absolute; altura: 1; largura: 1; topo: 0; Esquerda: 0;}
->
</style>
</head>
<Body>
<Script Language = "JavaScript1.2">
adTime = 5; // o tempo esperado da janela
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 = avaliar ('document.all.ponsoraddiv.style');
caso contrário, if (ns) addiv = eval ('document.layers ["sponsoraddiv"]');
caso contrário, if (w3) addiv = eval ('document.getElementById ("sponsoraddiv"). estilo');
Randad = Math.ceil (Math.random ()*Hancead);
se (ou seja || w3)
addiv.visibility = "visível";
outro
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;}
caso contrário, if (ns) {documentwidth = window.innerwidth/2+window.pagexoffset-20;
DocumentHeight = Window.innerHeight/2+window.pageyoffset-20;}
caso contrário, 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 () {
se (ou seja || w3)
addiv.display = "nenhum";
outro
addiv.visibility = "hide";
}
onLoad = initad;
</script>
<div id = "sponsoraddiv" style = "visibilidade: hidden">
<tabela bgcolor = "008000"> <tr> <td>
<tabela bgcolor = "f0fff0"> <tr> <td>
<Center> Bem -vindo ao www.csrcode.cn! <br> <br> Esta janela será bloqueada automaticamente em 5 segundos </fenter>
</td> </tr> </ table> </td> </tr> </tabela> </div>
</body>
</html>
Espero que este artigo seja útil para a programação JavaScript de todos.