案例分析:点击按钮后,在网页上指定区域,提示错误信息!5秒后,错误信息提示自动消失!

 

 1    <script languag="javascript" type="text/javascript">
 2        var clearId;
 3        function test(){
 4            document.getElementById("showMsg").style.cssText="width:200px;height:50px;left:600px;top:100px;position:absolute;background-color:red;";
 5            document.getElementById("showMsg").innerText = "输入的有错误!请重新输入!";
 6            clearId = setTimeout("autoClearError()",5000);
 7        }
 8 
 9        function autoClearError(){
10             document.getElementById("showMsg").style.cssText="";
11             document.getElementById("showMsg").innerText = ""
12             clearTimeout(clearId);
13        }
14    </script>
15  </head>
16  <body>
17     <input type="button" value="删除" onclick="test();" />
18     <div id="showMsg"></div>
19  </body>