可以文本显示的公告栏的js代码
程序员文章站
2023-11-21 15:23:40
一个可以文本显示的公告栏,可以在多处使用,绝对不可错过! 脚本说明: 第一步:把如下代码加入区域中
一个可以文本显示的公告栏,可以在多处使用,绝对不可错过!
脚本说明:
第一步:把如下代码加入<head>区域中
<script language="javascript">
<!-- activate cloaking device
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="rn";
// each element of textinput represents a single message.
textinput[0] = "今天注意了有新的任务布置";
textinput[1] = "欢迎你的光临!本站为你提供大量javascript下载";
textinput[2] = "重点介绍javascript";
textinput[3] = "与制作网页特效密切相关的技术";
textinput[4] = "本站同时有影音空间等栏目";
textinput[5] = "还有新闻及健康方面的资料";
textinput[6] = "还有宽带网方面的大量技术文章";
textinput[7] = "本站网址:http://www.njcatv.net";
totaltextinput = 7; // (0, 1, 2, 3, 4, 5, 6, 7)
// positioning and speed vary between versions.
var version = navigator.appversion;
if (version.substring(0, 1)==3)
{
speed=200;
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("this is the end of the list!");
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="rn manual tele-type display";
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("this is the beginning of the list!");
timerset=false;
}
else
{
textnumber-=1;
message=textnumber+1;
document.forms[0].elements[2].value= message;
text = textinput[textnumber];
helptext = text;
}
teletype();
}
}
// deactivate cloaking --></script>
第二步:在<body>区域中加入如下代码:
<form>
<table cellspacing="0" cellpadding="0" width="17%">
<tr>
<td width="100%" colspan="3" valign="top"><div align="center"><p><textarea name="teletype" rows="3" cols="28" wrap="yes"></textarea> </td>
</tr>
<tr align="center">
<td width="40%" valign="top" bgcolor="#0000a0"><input type="button" value="公告栏" onclick="lastmessage()"></td>
<td width="30%" bgcolor="#0000a0" valign="top"><input type="text" value="共8条" size="5" name="1"></td>
<td width="30%" bgcolor="#0000a0" valign="top"><input type="button" value="阅 读" onclick="nextmessage()"></td>
</tr>
</table>
</form>
脚本说明:
第一步:把如下代码加入<head>区域中
<script language="javascript">
<!-- activate cloaking device
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="rn";
// each element of textinput represents a single message.
textinput[0] = "今天注意了有新的任务布置";
textinput[1] = "欢迎你的光临!本站为你提供大量javascript下载";
textinput[2] = "重点介绍javascript";
textinput[3] = "与制作网页特效密切相关的技术";
textinput[4] = "本站同时有影音空间等栏目";
textinput[5] = "还有新闻及健康方面的资料";
textinput[6] = "还有宽带网方面的大量技术文章";
textinput[7] = "本站网址:http://www.njcatv.net";
totaltextinput = 7; // (0, 1, 2, 3, 4, 5, 6, 7)
// positioning and speed vary between versions.
var version = navigator.appversion;
if (version.substring(0, 1)==3)
{
speed=200;
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("this is the end of the list!");
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="rn manual tele-type display";
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("this is the beginning of the list!");
timerset=false;
}
else
{
textnumber-=1;
message=textnumber+1;
document.forms[0].elements[2].value= message;
text = textinput[textnumber];
helptext = text;
}
teletype();
}
}
// deactivate cloaking --></script>
第二步:在<body>区域中加入如下代码:
<form>
<table cellspacing="0" cellpadding="0" width="17%">
<tr>
<td width="100%" colspan="3" valign="top"><div align="center"><p><textarea name="teletype" rows="3" cols="28" wrap="yes"></textarea> </td>
</tr>
<tr align="center">
<td width="40%" valign="top" bgcolor="#0000a0"><input type="button" value="公告栏" onclick="lastmessage()"></td>
<td width="30%" bgcolor="#0000a0" valign="top"><input type="text" value="共8条" size="5" name="1"></td>
<td width="30%" bgcolor="#0000a0" valign="top"><input type="button" value="阅 读" onclick="nextmessage()"></td>
</tr>
</table>
</form>