44、頁面的開啟移動
把如下程式碼加入<body>區域中
<SCRIPT LANGUAGE="JavaScript"> <!-- Begin for (t = 2; t > 0; t--) { for (x = 20; x > 0; x--) { for (y = 10; y > 0; y--) { parent.moveBy(0,-x); } } for (x = 20; x > 0; x--) { for (y = 10; y > 0; y--) { parent.moveBy(0,x); } } for (x = 20; x > 0; x--) { for (y = 10; y > 0; y--) { parent.moveBy(x,0); } } for (x = 20; x > 0; x--) { for (y = 10; y > 0; y--) { parent.moveBy(-x,0); } } } //--> // End --> </script> |
45、顯示個人客戶端機器的日期和時間
<script language="LiveScript"> <!-- Hiding today = new Date() ***("現在時間是: ",today.getHours(),":",today.getMinutes()) ***(" <br>今天日期為: ", today.getMonth()+1,"/",today.getDate(),"/",today.getYear()); // end hiding contents --> </script> |
46.自動的為你每次產生最後修改的日期了:
<html> <body> This is a simple HTML- page. <br> Last changes: <script language="LiveScript"> <!-- hide script from old browsers ***(document.lastModified) // end hiding contents --> </script> </body> </html> |
47、不能為空和郵件地址的約束:
<html> <head> <script language="JavaScript"> <!-- Hide function test1(form) { if (form.text1.value == "") alert("您沒寫上任何東西, 請再輸入一次!") else { alert("嗨"+form.text1.value+"! 您已輸入完成!"); } } function test2(form) { if (form.text2.value == "" || form.text2.value.indexOf('@', 0) == -1) alert("這不是正確的e-mail address! 請再輸入一次!"); else alert("您已輸入完成!"); } // --> </script> </head> <body> <form name="first"> Enter your name: <br> <input type="text" name="text1"> <input type="button" name="button1" value="輸入測試" onClick="test1(this.form)"> <P> Enter your e-mail address: <br> <input type="text" name="text2"> <input type="button" name="button2" value="輸入測試" onClick="test2(this.form)"> </body> |
48、跑馬燈
<html> <head> <script language="JavaScript"> <!-- Hide var scrtxt="怎麽樣! 很酷吧! 你也可以試試."+"Here goes your message the visitors to your page will "+"look at for hours in pure fascination..."; var lentxt=scrtxt.length; var width=100; var pos=1-width; function scroll() { pos++; var scroller=""; if (pos==lentxt) { pos=1-width; } if (pos <0) { for (var i=1; i <=Math.abs(pos); i++) { scroller=scroller+" ";} scroller=scroller+scrtxt.substring(0,width-i+1); } else { scroller=scroller+scrtxt.substring(pos,width+pos); } window.status = scroller; setTimeout("scroll()",150); } //--> </script> </head> <body onLoad="scroll();return true;"> 這裡可顯示您的網頁! </body> </html> |
49、在網頁中用按鈕來控制前頁,後頁和首頁的顯示。
<html> <body> <FORM NAME="buttonbar"> <INPUT TYPE="button" VALUE="Back" onClick="history.back()"> <INPUT TYPE="button" VALUE="JS- Home" onClick="location='script.html'"> <INPUT TYPE="button" VALUE="Next" onCLick="history.forward()"> </FORM> </body> </html> |
50、查看某網址的源碼
把如下程式碼加入<body>區域中
<SCRIPT> function add() { var ress=document.forms[0].luxiaoqing.value window.location="view-source:"+ress; } </SCRIPT> 輸入要查看原始碼的URL位址: <FORM> <input type="text" name="luxiaoqing" size=40 value="http://"> </FORM> <FORM> <br> <INPUT type="button" value="查看原始碼" onClick=add()> </FORM> |
51、title顯示日期
把如下程式碼加入<body>區域中:
<script language="JavaScript1.2"> <!--hide var isnMonth = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); var isnDay = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日"); today = new Date () ; Year=today.getYear(); Date=today.getDate(); if (document.all) document.title="今天是: "+Year+"年"+isnMonth[today.getMonth()]+Date+"日"+isnDay[today.getDay()] //--hide--> </script> |