转自javascript.com.cn(放在这里主要是方便我自己的学习,如果不允许的话,请通知我,我将自行删除)
26访问document对象
<scriptlanguage=”JavaScript”> varmyURL=document.URL; window.alert(myURL); </script>
27动态输出HTML
<scriptlanguage=”JavaScript”> document.write(“<p>Here’ssomeinformationaboutthisdocument:</p>”); document.write(“<ul>”); document.write(“<li>ReferringDocument:“+document.referrer+“</li>”); document.write(“<li>Domain:“+document.domain+“</li>”); document.write(“<li>URL:“+document.URL+“</li>”); document.write(“</ul>”); </script>
28输出换行
document.writeln(“<strong>a</strong>”); document.writeln(“b”);
29输出日期
<scriptlanguage=”JavaScript”> varthisDate=newDate(); document.write(thisDate.toString()); </script>
30指定日期的时区
<scriptlanguage=”JavaScript”> varmyOffset=-2; varcurrentDate=newDate(); varuserOffset=currentDate.getTimezoneOffset()/60; vartimeZoneDifference=userOffset-myOffset; currentDate.setHours(currentDate.getHours()+timeZoneDifference); document.write(“ThetimeanddateinCentralEuropeis:“+currentDate.toLocaleString()); </script>
31设置日期输出格式
<scriptlanguage=”JavaScript”> varthisDate=newDate(); varthisTimeString=thisDate.getHours()+“:”+thisDate.getMinutes(); varthisDateString=thisDate.getFullYear()+“/”+thisDate.getMonth()+“/”+thisDate.getDate(); document.write(thisTimeString+“on“+thisDateString); </script>
32读取URL参数
<scriptlanguage=”JavaScript”> varurlParts=document.URL.split(“?”); varparameterParts=urlParts[1].split(“&”); for(i=0;i<parameterParts.length;i++){ varpairParts=parameterParts[i].split(“=”); varpairName=pairParts[0]; varpairValue=pairParts[1]; document.write(pairName+“:“+pairValue); } </script>
你还以为HTML是无状态的么?
33打开一个新的document对象
<scriptlanguage=”JavaScript”> functionnewDocument(){ document.open(); document.write(“<p>ThisisaNewDocument.</p>”); document.close(); } </script>
34页面跳转
<scriptlanguage=”JavaScript”> window.location=“[url]http://www.liu21st.com/[/url]”; </script>
35添加网页加载进度窗口
<html> <head> <scriptlanguage='javaScript'> varplaceHolder=window.open('holder.html','placeholder','width=200,height=200'); </script> <title>TheMainPage</title> </head> <bodyonLoad='placeHolder.close()'> <p>Thisisthemainpage</p> </body> </html>