1.讓文字不停地滾動
<MARQUEE>滾動文字</MARQUEE>
2.記錄并顯示網頁的最后修改時間
<script?language=JavaScript>
document.write("最后更新時間:?"?+?document.lastModified?+?"")
</script>
3.關閉當前窗口
<a?href="/">關閉窗口</a>
4.2秒后關閉當前頁
<script?language="JavaScript">
<!--
setTimeout('window.close();',2000);
-->
</script>
5.2秒后載入指定網頁
<head>
<meta?http-equiv="refresh"?content="2;URL=http://你的網址">
</head>
6.添加到收藏夾
<Script?Language="JavaScript">
function?bookmarkit()
{
window.external.addFavorite('http://你的網址','你的網站名稱')
}
if?(document.all)document.write('<a?href="#"?onClick="bookmarkit()">加入收藏夾</a>')
</Script>
7.讓超鏈接不顯示下劃線
<style?type="text/css">
<!-
a:link{text-decoration:none}
a:hover{text-decoration:none}
a:visited{text-decoration:none}
->
</style>
8.禁止鼠標右鍵的動作
<Script??Language?=?"JavaScript">
function?click()?{?if?(event.button==2||event.button==3)
{
alert('禁止鼠標右鍵');
}
document.οnmοusedοwn=click?//?-->
</Script>
9.設置該頁為首頁
<body?bgcolor="#FFFFFF"?text="#000000">
<!--?網址:http://你的網址-->
<a?class="chlnk"?style="cursor:hand"?HREF
url(#default#homepage)';
this.setHomePage('你的網站名稱);"><font?color="000000"?size="2"?face="宋體">設為首頁</font></a>
</body>
中級篇
1.節日倒計時
<Script?Language="JavaScript">
var?timedate=?new?Date("October?1,2002");
var?times="國慶節";
var?now?=?new?Date();
var?date?=?timedate.getTime()?-?now.getTime();
var?time?=?Math.floor(date?/?(1000?*?60?*?60?*?24));
if?(time?>=?0)
document.write("現在離"+times+"還有:?"+time?+"天")</Script>
2.單擊按鈕打印出當前頁
<Script??Language="JavaScript">
<!--?Begin
if?(window.print)?{
document.write('<form>'
+?'<input?type=button?name=print?value="打印本頁"?'
+?'></form>');
}
//?End?-->
</Script>
3.單擊按鈕‘另存為’當前頁
<input?type="button"?name="Button"?value="保存本頁"
>
<object??id="button"
width=0
height=0
classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
<embed?width="0"???height="0"></embed>
</object>
4.顯示系統當前日期
<script?language=JavaScript>
today=new?Date();
function?date(){
this.length=date.arguments.length
for(var?i=0;i<this.length;i++)
this[i+1]=date.arguments[i]??}
var?d=new?date("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
document.write(
"<font?color=##000000?style='font-size:9pt;font-family:?宋體'>?",
today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日",
d[today.getDay()+1],"</font>"?);
</script>
高級篇
1.不同時間段顯示不同問候語
<Script?Language="JavaScript">
<!--
var?text="";???day?=?new?Date(?);??time?=?day.getHours(?);
if?((?time>=0)?&&?(time?<?7?))
text="夜貓子,要注意身體哦!?"
if?((?time?>=?7?)?&&?(time?<?12))
text="今天的陽光真燦爛啊,你那個朋友呢?"
if?((?time?>=?12)?&&?(time?<?14))
text="午休時間。您要保持睡眠哦!"
if?((?time?>=14)?&&?(time?<?18))
text="祝您下午工作愉快!?"
if?((time?>=?18)?&&?(time?<=?22))
text="您又來了,可別和MM聊太久哦!"
if?((time?>=?22)?&&?(time?<?24))
text="您應該休息了!"
document.write(text)
//--->
</Script>
2.水中倒影效果
<img?id="reflect"?src="你自己的圖片文件名"?width="175"?height="59">
<script?language="JavaScript">
function?f1()
{
setInterval("mdiv.filters.wave.phase+=10",100);
}
if?(document.all)
{
document.write('<img??id=mdiv??src="'+document.all.reflect.src+'"
style="filter:wave(strength=3,freq=3,phase=0,lightstrength=30)??blur()?flipv()">')
window.οnlοad=f1
}
</script>
3.慢慢變大的窗口
<Script?Language="JavaScript">
<!--
var?Windowsheight=100
var?Windowswidth=100
var?numx=5
function?openwindow(thelocation){
temploc=thelocation
if
(!(window.resizeTo&&document.all)&&!(window.resizeTo&&document.getElementById))
{
window.open(thelocation)
return
}
windowsize=window.open("","","scrollbars")
windowsize.moveTo(0,0)
windowsize.resizeTo(100,100)
tenumxt()
}
function?tenumxt(){
if?(Windowsheight>=screen.availHeight-3)
numx=0
windowsize.resizeBy(5,numx)
Windowsheight+=5
Windowswidth+=5
if?(Windowswidth>=screen.width-5)
{
windowsize.location=temploc
Windowsheight=100
Windowswidth=100
numx=5
return
}
setTimeout("tenumxt()",50)
}
//-->
</script>
<p><a?href=" src="http://www.jinjunhe.net/pic/url.gif" border=0>http://www.ccjol.com')">進入</a>
4.改變IE地址欄的IE圖標
我們要先做一個16*16的icon(圖標文件),保存為index.ico。把這個圖標文件上傳到根目錄下并在首頁<head></head>之間加上如下代碼:
<link?REL?=?"Shortcut?Icon"?href="index.ico">
5.讓網頁隨意后退
<a?href="">X</a>?//把X換成你想要后退在頁數
//把“-”變成“+”就為前進
6.鼠標指向時彈出信息框
在<body></body>之間加上如下代碼:
<a?href?οnmοuseοver="alert('彈出信息!')">顯示的鏈接文字</a>
7.單擊鼠標右鍵彈出添加收藏夾對話框
在<body></body>之間加上如下代碼:
<Script?Language=JavaScript>
if?(document.all)
document.body.οnmοusedοwn=new?Function("if?(event.button==2||event.button==3)
window.external.addFavorite('您的網址','您的網站名稱)")
</Script>
8.隨機變換背景圖象(一個可以刷新心情的特效)
在<head></head>之間加上如下代碼:
<Script?Language="JavaScript">
image?=?new?Array(4);???//定義image為圖片數量的數組
image?[0]?=?'tu0.gif'?????//背景圖象的路徑
image?[1]?=?'tu1.gif'
image?[2]?=?'tu2.gif'
image?[3]?=?'tu3.gif'
image?[4]?=?'tu4.gif'
number?=?Math.floor(Math.random()?*?image.length);
document.write("<BODY?BACKGROUND="+image[number]+">");
</Script>
9.鼠標一碰就給顏色看的鏈接
在<body></body>之間加上如下代碼:
<p?onMouseMove="anniu()">你敢碰我,我就給點顏色你看!</p>
<Script?Language?=?"VBScript">
sub?anniu
document.fgColor=int(256*256*256*rnd)
end?sub
</Script>
10.從天而降并有幻影效果的窗口
<head>
<Script?language="JavaScript">
function?move(x)?{
if(self.moveBy){
self.moveBy?(0,-800);
for(i?=?x;?i?>?0;?i--)
{
self.moveBy(0,3);
}
for(j?=?200;?j?>?0;?j--){??//如果你認為窗口抖動厲害,就200換成個位數
self.moveBy(0,j);
self.moveBy(j,0);
self.moveBy(0,-j);
self.moveBy(-j,0);
}
}
}
</Scrip>
<body?bgColor=#ffffff?οnlοad=move(280)>
</body>
</head>
11.表格的半透明顯示效果
在<head></head>之間加上如下代碼:
<style>
.alpha{filter:?Alpha(Opacity=50)}???//50表示50%的透明度
</style>
在<body></body>之間加上如下代碼:
<table?border="1"?width="100"?height="62"??class="alpha"?bgcolor="#F2A664"?>
<tr>
<td?width="100%"?height="62">
<div?align="center">很酷吧!</div>