公告跑馬燈
將下列程式碼複製至<head>程式碼</head>區內。
<b><font size="7"> <CENTER> <FORM> <TEXTAREA NAME="teletype" ROWS=10 COLS=55 wrap=yes style="border-style: solid; border-width: 1px" ></TEXTAREA> <TABLE BORDER=0 WIDTH=250> <TD align="center"> <INPUT TYPE="button" VALUE="回顧訊息" onClick="lastMessage()" style="letter-spacing: 3pt; border-style: solid; border-width: 1px"> <TD align="center"> <INPUT TYPE="text" SIZE=4 name="a1" style="background-color: #FFFFFF; letter-spacing: 3pt; border-style: solid; border-width: 1px"> <TD align="center"> <INPUT TYPE="button" VALUE="瀏覽訊息" onClick="nextMessage()" style="color: #000000; border-style: solid; border-width: 1px"> </TABLE> </FORM> |
將下列程式碼複製至<body>程式碼</body>之間。
<SCRIPT> <!-- Activate Cloaking Device // used to track position in message var i = 0; // used to cycle thru messages var TextNumber = -1; // array of messages var TextInput = new Object(); // used to load manipulate message var HelpText=""; // used to load message var Text = ""; // length of timeout (smaller is faster) var Speed=50; // used to display message number var message=0; // used to position text in ver 2.0 var addPadding="\r\n"; // Each element of TextInput represents a single message. TextInput[0] = "這是第一列的訊息,可自訂。"; TextInput[1] = "這是第二列的訊息,可自訂。"; TextInput[2] = "這是第三列的訊息,可自訂。"; TextInput[3] = "這是第四列的訊息,可自訂。"; TotalTextInput = 3; // (0, 1, 2, 3, 4) // Positioning and speed vary between versions. var Version = navigator.appVersion; if (Version.substring(0, 1)==3) { Speed=100; addPadding=""; } for (var addPause = 0; addPause <= TotalTextInput; addPause++) {TextInput[addPause]=addPadding+TextInput[addPause];} var TimerId var TimerSet=false; // Called by >>> button (display next message) . function nextMessage() { if (!TimerSet) { TimerSet=true; clearTimeout (TimerId); if (TextNumber>=TotalTextInput) { alert("訊息最末端.再後面己無訊息!"); TimerSet=false; } else { TextNumber+=1; message=TextNumber+1; document.forms[0].elements[2].value= message; Text = TextInput[TextNumber]; HelpText = Text; } teletype(); } } // Gets and displays character from rollMessage() . // Variable Speed controls length of timeout and thus the speed of typing. function teletype() { if (TimerSet) { Text=rollMessage(); TimerId = setTimeout("teletype()", Speed); document.forms[0].elements[0].value=Text; } } // Pulls one character at a time from string and returns (as Text) to function teletype() for displaying. function rollMessage () { i++; var CheckSpace = HelpText.substring(i-1, i); CheckSpace = "" + CheckSpace; if (CheckSpace == " ") {i++;} if (i >= HelpText.length+1) { TimerSet=false; Text = HelpText.substring(0, i); i=0; return (Text); } Text = HelpText.substring(0, i); return (Text); } // Initially called by onLoad in BODY tag to load title. function initTeleType() { Text="\r\n 請按下面按鈕可看公告訊息"; document.forms[0].elements[0].value=Text; } // Called by <<< button (get previous message). function lastMessage() { if (!TimerSet && TextNumber!=-1) { TimerSet=true; clearTimeout (TimerId); if (TextNumber<=0) { alert("訊息最前端.再前面己無訊息!"); TimerSet=false; } else { TextNumber-=1; message=TextNumber+1; document.forms[0].elements[2].value= message; Text = TextInput[TextNumber]; HelpText = Text; } teletype(); } } // Deactivate Cloaking --> </SCRIPT> |