喜歡製作網頁的會用到的代碼(很全哦)

典型特效 
1、收藏本站
說明:點擊即可把你的網站添加到瀏覽器的收藏菜單下
代碼
<span style="CURSOR: hand" onClick="window.external.addFavorite('http://www.www.ycrc.com.cn','鹽城人才網')" title="收藏鹽城人 
才網">收藏本站</span>

2、設爲首頁
說明:點擊即可把你的網站設置爲瀏覽器的起始頁
代碼:
<span 
strHref=window.location.href;this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.ycrc.com.cn');" 
style="CURSOR: hand">設爲首頁</span>

3、去掉超鏈接的下劃線
說明:有時候看着那超鏈接的下劃線挺討厭的,把下面這段代碼放到網頁源代碼<head>與</head>之間,下劃線就無影無蹤啦! 
注意,網頁的<body>標籤裏不能再有link之類的屬性,否則本效果會失效!
代碼:
<style TYPE="text/css">
<!--
A:link{text-decoration:none}
A:visited{text-decoration:none}
A:hover {color: #ff00ff;text-decoration:underline}
-->
</style>

4、自動刷新網頁
說明:在HTML的與之間加入下面這段代碼,則在5分鐘之後正在瀏覽的頁面將會自動變爲target.html這一頁。代碼中300爲刷新的延遲時間,以 
秒爲單位。targer.html爲你想轉向的目標頁,若爲本頁則爲自動刷新本頁。
代碼:
<meta http-equiv="refresh" content="300; url=target.html">

5、刷新本頁
說明:點擊即可刷新本頁。
代碼:
<a href="javascript:location.reload()" target="_self">刷新</a>

6、返回到上一頁
說明:點擊即可返回到上一頁面。
代碼:
<a href="javascript:history.back(-1)">返回上一頁</a>

7、跳出小窗口
說明:在打開有下面這段代碼的頁面時將會跳出一個468x60大小的小窗口。“window.html”爲跳出的小窗口裏所要顯示的網頁。toolbar、sta 
tus、menubar、scrollbars、設置小窗口的工具欄、狀態欄、菜單欄及滾動條的有無,resizable設置是否可讓瀏覽者改變小窗口大小,width 
、height設置小窗口的寬度以及高度。(不過這樣的小窗口一般是不受歡迎的哦!) 
代碼:
<script language="JavaScript">
window.open("window.html","www_ycrc_com_cn","toolbar=no, status=no,menubar=no, 
scrollbars=no,resizable=no,width=468,height=60,left=200,top=50");
</script>

8、自動關閉窗口
說明:在網頁源代碼中加入下面的代碼,則該窗口將在20秒鐘之後自動關閉!這與跳出式小窗口配合使用是再好不過啦!代碼中“i=20”表示 
關閉的延遲時間爲20秒,可任意修改。
代碼:
<script language="javascript">
<!--
function clock(){i=i-1
document.title="本窗口將在"+i+"秒後自動關閉!";
if(i>0)setTimeout("clock();",1000);
else self.close();}
var i=20
clock();
//-->
</script>

9、給頁面加保護
說明:如果你不想讓辛辛苦苦做出來的東西被人輕易地Copy&aste走的話,不妨在HTML里加入下面這段代碼。當在網頁裏按下鼠標右鍵時,出 
現的不是想要的快捷菜單而是一個警告窗口。“/n/n”表示換行。 
代碼:
<script language="JavaScript">
function ycrc_com_cn()
{
if (event.button==2)alert(' 僅供瀏覽!謝謝!/n/n若有問題請與我聯繫! ')
}
</script>

然後把<body> 改爲
<body οnmοusedοwn="ycrc_com_cn()">

10、固定字號大小
說明:你是否有過這樣的經歷:一個佈置得很好的網頁,當瀏覽時把瀏覽器的字號設置成大或小時,漂亮的網頁馬上面目全非了。因爲字的大 
小變了,版式自然亂了。現在好了,只要把下面這段代碼加入到網頁源文件的<head>與</head>之間就行了(對用<font>標籤定義的文字無效)。 
代碼:
<style type="text/css">
<!--
body {font-size:9pt}
td {font-size:9pt}
-->
</style>

11、狀態欄裏的動態歡迎語
說明:瀏覽器的狀態欄裏出現一個字接一個字往左跑的歡迎語!
代碼:
<script language="JavaScript">
<!--
function statusMessageObject(p,d) {
this.msg = MESSAGE
this.out = " "
this.pos = POSITION
this.delay = DELAY
this.i = 0
this.reset = clearMessage
}
function clearMessage() {
this.pos = POSITION
}
var POSITION = 100
var DELAY = 5
var MESSAGE = "歡迎光臨! Welcome to WWW.YCRC.COM.CN "
var scroll = new statusMessageObject()
function scroller() {
for (scroll.i = 0; scroll.i < scroll.pos; scroll.i++) {
scroll.out += " "
}
if (scroll.pos >= 0)
scroll.out += scroll.msg
else scroll.out = scroll.msg.substring(-scroll.pos,scroll.msg.length)
window.status = scroll.out
scroll.out = " "
scroll.pos--
if (scroll.pos < -(scroll.msg.length)) {
scroll.reset()
}
setTimeout ('scroller()',scroll.delay)
}
function snapIn(jumpSpaces,position) {
var msg = scroll.msg
var out = ""
for (var i=0; i<position; i++)
{out += msg.charAt(i)}
for (i=1;i<jumpSpaces;i++)
{out += " "}
out += msg.charAt(position)
window.status = out
if (jumpSpaces <= 1) {
position++
if (msg.charAt(position) == ' ')
{position++ }
jumpSpaces = 100-position
} else if (jumpSpaces > 3)
{jumpSpaces *= .75}
else
{jumpSpaces--}
if (position != msg.length) {
var cmd = "snapIn(" + jumpSpaces + "," + position + ")";
scrollID = window.setTimeout(cmd,scroll.delay);
} else {
window.status=""
jumpSpaces=0
position=0
cmd = "snapIn(" + jumpSpaces + "," + position + ")";
scrollID = window.setTimeout(cmd,scroll.delay);
return false
}
return true
}
snapIn(100,0);
// -->
</script>

12、保護自己的頁面不被別人放在框架中
說明:有些人真是懶得可以,把別人做好的網頁往自己網頁的框架(Frame)裏一放,別人的成果就變成了自己的,而且看不出該網頁的真實地址 
!爲了防止你的成果被這些人所剽竊,你就可以在你網頁的HTML里加入下面這段代碼,這樣,你的網頁便總是在整個窗口中打開了。
代碼:
<Script LANGUAGE="JavaScript">
if(self!=top){top.location=self.location;}
</script>

按鈕特效

13、全屏顯示
說明:真正的全屏顯示,只能用ALT+F4關閉
代碼:
<input type="BUTTON" name="FullScreen" value="全屏顯示" onClick="window.open(document.location, 'www_ycrc_com_cn', 
'fullscreen')">

14、打開一個全屏窗口
說明:用按鈕打開一個全屏窗口
代碼:
<input type="button" onClick="www_ycrc_com_cn()" value="試試看" name="button">

<script>
<!--
function www_ycrc_com_cn(){
var targeturl="http://www.ycrc.com.cn"
newwin=window.open("","","scrollbars")
if (document.all){
newwin.moveTo(0,0)
newwin.resizeTo(screen.width,screen.height)
}
newwin.location=targeturl
}
//-->
</script>

15、各種用途的按鈕大集合
說明:各種用途的按鈕大集合
代碼:
<input TYPE="button" NAME="view" VALUE="查看源代碼" OnClick="window.location='view-source:' +window.location.href" >

<input TYPE="button" VALUE="返回上一步" ONCLICK="history.back(-1)">

<input TYPE="button" VALUE="刷新按鈕一" ONCLICK="ReloadButton()">
<script language="JavaScript">
<!--
function ReloadButton(){location.href="3.html";}
// -->
</script>

<p>
<input TYPE="button" VALUE="刷新按鈕二" onClick="history.go(0)">

<input TYPE="button" VALUE="回首頁按鈕" ONCLICK="HomeButton()">
<script language="JavaScript">
<!--
function HomeButton(){location.href="http://www.ycrc.com.cn";}
// -->
</script>

<input TYPE="button" VALUE="彈出警告框" ONCLICK="AlertButton()">
<script language="JavaScript">
<!--
function AlertButton(){window.alert("今天你喝了沒有?");}
// -->
</script>

<p>
<input TYPE="button" VALUE="狀態欄信息" ONCLICK="StatusButton()">
<script language="JavaScript">
<!--
function StatusButton(){window.status="你好嗎?";}
// -->
</script>

<input TYPE="button" VALUE="背景色變換" onClick="BgButton()">
<script language="JavaScript">
<!--
function BgButton(){
if (document.bgColor=='#3399ff')
{document.bgColor='#00ccff';}
else{document.bgColor='#3399ff';}
}
// -->
</script>

<input TYPE="button" VALUE="打開新窗口" ONCLICK="NewWindow()">
<script language="JavaScript">
<!--
function 
NewWindow(){window.open("http://www.ycrc.com.cn","","height=600,width=800,left=10,top=10,status=no,location=no,toolbar=no, 
directories=no,menubar=no");}
// -->
</script>

16、特殊效果的按鈕
說明:特殊效果的按鈕
代碼:
<style type="text/css">
<!--
.over {color:yellow; background: navy}
.down {color:yellow; background: navy; font-style: italic}
-->
</style>
<input
type="Button" value="按鈕也瘋狂" name="Button"
onMouseOver="this.className='over';"
onMouseOut="this.className='';this.value='按鈕也瘋狂'"
onMouseDown="this.className='down';"
onMouseUp="this.className='over';"
onClick="this.value='我真的好喜歡你!'">

17、讓屏幕抖動一陣
說明:讓屏幕抖動一陣
代碼:
<input type="button" value="地震啦!!!">
<script language="JavaScript">
<!--
function surfto(form) {
var myindex=form.select1.selectedIndex
if (form.select1.options[myindex].value != null) {
parent.main.location.href=form.select1.options[myindex].value;
}
}
// -->
</script>
<script language="JavaScript1.2">
<!--
function www_ycrc_com_cn(n) {
if (window.top.moveBy) {
for (i = 10; i > 0; i--) {
for (j = n; j > 0; j--) {
window.top.moveBy(0,i);
window.top.moveBy(i,0);
window.top.moveBy(0,-i);
window.top.moveBy(-i,0);
}
}
}
alert(" 沒嚇壞吧!!! ");
}
// -->
</script>
頁面背景

..................
..................

發佈了22 篇原創文章 · 獲贊 12 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章