Este artículo describe el método de JS para bloquear automáticamente la capa DIV en 5 segundos. Compártelo para su referencia. El método de implementación específico es el siguiente:
Copie el código de la siguiente manera: <html>
<Evista>
<title> JS implementa el bloqueo automático de la capa Div en 5 segundos </title>
<style type = "text/css">
<!-
#sponsorAddiv {posición: absoluto; Altura: 1; Ancho: 1; arriba: 0; Izquierda: 0;}
->
</style>
</ablo>
<Body>
<Script language = "javaScript1.2">
adtime = 5; // El tiempo esperado de la ventana
Chancoad = 1;
var ns = (document.layers);
var ie = (document.all);
var w3 = (document.getElementById &&! Ie);
adcount = 0;
función initad () {
if (! ns &&! ie &&! w3) return;
if (es decir) addiv = eval ('document.all.sponsoraddiv.style');
else if (ns) addiv = eval ('document.layers ["SPatonsorAdDiv"]');
else if (w3) addiv = eval ('document.getElementById ("SPatonsorAdDiv"). Style');
randad = math.ceil (math.random ()*hancaad);
if (es decir, w3)
addiv.visibility = "visible";
demás
addiv.visibility = "show";
if (randad == 1) showad ();
}
función showad () {
if (adcount <adtime*10) {adcount+= 1;
if (es decir) {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 cerrado ();
}
function searead () {
if (es decir, w3)
addiv.display = "ninguno";
demás
addiv.visibility = "Ocultar";
}
onload = initad;
</script>
<div id = "STPONSORADDIV" style = "Visibility: Hidden">
<tabla bgcolor = "008000"> <tr> <td>
<tabla bgcolor = "f0fff0"> <tr> <td>
<Center> Bienvenido a www.csrcode.cn! <br> <br> Esta ventana se bloqueará automáticamente en 5 segundos </center>
</td> </tr> </table> </td> </tr> </table> </div>
</body>
</html>
Espero que este artículo sea útil para la programación de JavaScript de todos.