js 小知识

时间:2014-05-09 04:34:03   收藏:0   阅读:397
bubuko.com,布布扣
1     window事件
2       window.onload=function(){alert("页面创建中****");};
3         window.onunload=function(){alert("页面卸载中****");};
4         window.onbeforedeactivate =function(){alert("页面卸载中****")};
bubuko.com,布布扣

定时

bubuko.com,布布扣
 1         window.status="xxxxx"
 2         var now =new Date().toLocaleString();
 3         window.status=now;
 4 
 5         function showTime()
 6         {
 7             var now=new Date().toLocaleString();
 8             window.status=now;
 9             //window.document.write(window.status+"<br/>");
10             window.document.getElementById("time").innerText=window.status;
11 
12         }
13         //window.setInterval("showTime()",1000);
14 
15         //window.location.href="http://127.0.0.1:8080/bbs";
16         
17         var size=window.history.length;            //浏览器的历史栏,它存放的是该浏览器窗口已访问过的网页内容
18         window.document.write(size);
19         
20         //打开新的窗口
21         var newWindow=window.open("function.html");
22         
23         newWindow.close();
bubuko.com,布布扣

触发事件,表单提交是否

bubuko.com,布布扣
 1     <form name="register" action="http://127.0.0.1:8080/bbs" method="post" onsubmit="return checkRegister()">
 2         <input type="text" name="username" /> 
 3         <input type="submit" value="注册" />
 4     </form>
 5 
 6     <form action="#" method="post" onsubmit="return checkLogin()">
 7         <input type="text" name="username" />
 8          <input type="submit" value="登录" />
 9     </form>
10 
11     <script type="text/javascript">
12         function checkRegister()
13         {
14             var name=window.document.register.username.value;
15             alert(name);
16             return false;
17         }
18         function checkLogin()
19         {
20             var name=window.document.forms[1].username.value;
21             alert(name);
22             return false;
23         }
24     </script>
bubuko.com,布布扣

打开新窗口

bubuko.com,布布扣
1     <script type="text/javascript">
2 
3         
4         //打开新的窗口
5         var newWindow=window.open("function.html");
6         
7         newWindow.close();
8     </script>
bubuko.com,布布扣

 

js 小知识,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!