提示:您可以先修改部分代碼再運行
<html><head><title>js 按時消失的連結</title><script language="javascript"><!--表示顯示的資訊-->var message='<b>按時消失的連結(5秒後自動消失)</b>'<!--定義背景色-->var backgroundcolor="#00FFFF"<!--0 代表資訊永遠顯示,1 代表資訊只顯示一段時間,2為隨機顯示模式-->var displaymode=1<!--如果顯示模式為在指定時間內顯示,輸入時間段(1000為1秒)-->var displayduration=5000<!--1代表閃爍,0代表不閃爍;-->var flashmode=1<!--如果設定了閃爍,輸入閃爍的顏色-->var flashtocolor="#FFFF00"function regenerate(){window.location.reload()<!--重新載入視窗-->}var which=0function regenerate2(){if (document.layers) <!--如果是netscape瀏覽器,則延時700ms-->setTimeout("window.onresize=regenerate",700)}function display2(){if (document.layers){ <!--如果是netscape瀏覽器-->if (topmsg.visibility=="show")<!--如果資訊是可見的則改為隱藏-->topmsg.visibility="hide"elsetopmsg.visibility="show" <!--否則改為可見-->}else if (document.all){ <!--如果是ie瀏覽器-->if (topmsg.style.visibility=="visible")topmsg.style.visibility="hidden" <!--如果資訊是可見的改為隱藏,否則改為可見-->elsetopmsg.style.visibility="visible"setTimeout("display2()",Math.round(Math.random()*10000)+10000) <!--延時一個隨機時間-->}}function flash(){if (which==0){ <!--如果which為0-->if (document.layers) <!--netscape瀏覽器-->topmsg.bgColor=flashtocolor<!--資訊的背景色改為閃爍的顏色-->elsetopmsg.style.backgroundColor=flashtocolor <!--ie時也是相同的操作-->which=1 <!--將which置為1-->}else{if (document.layers) <!--netscape瀏覽器-->topmsg.bgColor=backgroundcolor<!--設定連結的背景顏色-->else<!--ie瀏覽器-->topmsg.style.backgroundColor=backgroundcolor<!--設定連結的背景顏色-->which=0<!--將which置0-->}}if (document.all){<!--ie瀏覽器-->document.write('<span id="topmsg" >'+message+'</span>')<!--顯示連結的內容-->}Ypos = window.document.body.clientHeight - 60;Xpos = window.document.body.clientWidth - 60;function logoit(){document.all.topmsg.style.left=document.body.scrollLeft+document.body.clientWidth/2<!--設定連結顯示的左邊界-->document.all.topmsg.style.top=document.body.scrollTop+document.body.clientHeight<!--設定連結顯示的上邊界-->}function setmessage(){<!--顯示連結-->document.all.topmsg.style.backgroundColor=backgroundcolor<!--設定連結的背景色-->document.all.topmsg.style.visibility="visible"<!--設定連結為可視-->if (displaymode==1)<!--如果是模式1-->setTimeout("topmsg.style.visibility='hidden'",displayduration)<!--按照設定的時間延時後,將連結的顯示內容變成隱藏-->else if (displaymode==2)<!--如果是模式2-->display2()<!--直接調用display2函數-->if (flashmode==1)setInterval("flash()",1000)<!--設定flash的延時1秒-->window.onscroll=logoit<!--設定事件對應的函數-->window.onresize=new Function("window.location.reload()")<!--重新載入視窗-->}function setmessage2(){<!--顯示連結-->topmsg=new Layer(window.innerWidth)<!--信件一個層,寬度固定-->topmsg.bgColor=backgroundcolor<!--設定連結的背景色-->regenerate2()topmsg.document.write(message)<!--輸出連結-->topmsg.document.close()logoit2()<!--調用函數logoit2函數-->topmsg.visibility="show"<!--設定連結的顯示內容-->if (displaymode==1)<!--如果是模式 1-->setTimeout("topmsg.visibility='hide'",displayduration)<!--按照設定的時間延時後,將連結的顯示內容變成隱藏-->else if (displaymode==2)<!--如果是模式2-->display2()<!--直接調用display2函數-->if (flashmode==1)setInterval("flash()",1000)<!--設定flash的延時1秒-->}if (document.layers)<!--如果時netscape瀏覽器-->window.onload=setmessage2<!--調用setmessage2函數-->else if (document.all)<!--如果是ie瀏覽器-->window.onload=setmessage<!--調用setmessage函數--></script></body></html><!--本常式實現了按時消失的連結--><!--延時函數的使用方法--><!--連結的使用--><!--控制連結的背景顏色-->
提示:您可以先修改部分代碼再運行