您现在的位置: 网页制作教程网 >> 网页特效 >> Javascript 教程 >> 文章正文

初学网页Javascript经典小教程总结

作者:warm-ice

来源:闪吧

热度:

2006-9-10 13:47:45



23 定时执行函数 

1: <script> 
2: <!-- 
3: function hello() {  
4: window.alert(“Hello”); 
5: window.setTimeout(“hello()”,5000); 
6: } 
7: window.setTimeout(“hello()”,5000); 
8: // --> 
9: </script>  

24 取消定时执行 

1: <script> 
2: <!-- 
3: function hello() {  
4: window.alert(“Hello”); 
5: } 
6: var myTimeout = window.setTimeout(“hello()”,5000); 
7: window.clearTimeout(myTimeout); 
8: // --> 
9: </script>  

25 在页面卸载时候执行函数 

1: <body onUnload=”functionName();”> 
2: Body of the page 
3: </body>  

JavaScript就这么回事2:浏览器输出  

26 访问document对象 

1: <script language=”JavaScript”> 
2: var myURL = document.URL; 
3: window.alert(myURL); 
4: </script>  

27 动态输出HTML 

1: <script language=”JavaScript”> 
2: document.write(“<p>Here’s some information about this document:</p>”); 
3: document.write(“<ul>”); 
4: document.write(“<li>Referring Document: “ + document.referrer + “</li>”); 
5: document.write(“<li>Domain: “ + document.domain + “</li>”); 
6: document.write(“<li>URL: “ + document.URL + “</li>”); 
7: document.write(“</ul>”); 
8: </script>  


28 输出换行 

1: document.writeln(“<strong>a</strong>”); 
2: document.writeln(“b”);  

29 输出日期 

1: <script language=”JavaScript”> 
2: var thisDate = new Date(); 
3: document.write(thisDate.toString()); 
4: </script>  

30 指定日期的时区 

1: <script language=”JavaScript”> 
2: var myOffset = -2; 
3: var currentDate = new Date(); 
4: var userOffset = currentDate.getTimezoneOffset()/60; 
5: var timeZoneDifference = userOffset - myOffset; 
6: currentDate.setHours(currentDate.getHours() + timeZoneDifference); 
7: document.write(“The time and date in Central Europe is: “ + currentDate.toLocaleString()); 
8: </script>  

31 设置日期输出格式 

1: <script language=”JavaScript”> 
2: var thisDate = new Date(); 
3: var thisTimeString = thisDate.getHours() + “:” + thisDate.getMinutes(); 
4: var thisDateString = thisDate.getFullYear() + “/” + thisDate.getMonth() + “/” + thisDate.getDate(); 
5: document.write(thisTimeString + “ on “ + thisDateString); 
6: </script>  

32 读取URL参数 

1: <script language=”JavaScript”> 
2: var urlParts = document.URL.split(“?”); 
3: var parameterParts = urlParts[1].split(“&”); 
4: for (i = 0; i < parameterParts.length; i++) {  
5: var pairParts = parameterParts[i].split(“=”); 
6: var pairName = pairParts[0]; 
7: var pairValue = pairParts[1]; 
8: document.write(pairName + “ :“ +pairValue ); 
9: } 
10: </script>  

你还以为HTML是无状态的么? 

33 打开一个新的document对象 

1: <script language=”JavaScript”> 
2: function newDocument() {  
3: document.open(); 
4: document.write(“<p>This is a New Document.</p>”); 
5: document.close(); 
6: } 
7: </script>  

34 页面跳转 

1: <script language=”JavaScript”> 
2: window.location = “http://www.webjx.com/”; 
3: </script>  

上一页  [1] [2] [3] [4] [5] 下一页

我来说两句:

1分 2分 3分 4分 5分
姓名: *


* 请各位网友遵纪守法并注意语言文明。