定时显示div

时间:2022-11-13 21:40:38
<!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>
<style type="text/css">
#div1{
width:100px;
height:100px;
background:pink;
display:none;
}
</style>
</head><body>
<p>2秒后自动显示这个层</p>
<div id="div1"></div>
<script type="text/javascript">
var div1=document.getElementById("div1");
function show(){
div1.style.display="block";
}
setTimeout(show,2000);
</script>
</body>
</html>