Javascript水平滚动文字,改变颜色

时间:2014-11-21 09:52:27

标签: javascript

我是javascript的新手,我需要更改此脚本中文本的颜色:

<script language="javascript">
<!--
var bannerID=0
function text(msg,ctrlwidth) {
msg = " --- "+msg
newmsg = msg
while (newmsg.length < ctrlwidth) {
newmsg += msg
}
document.write ('<FORM NAME="Scrolltext">');
document.write ('<CENTER><INPUT NAME="text" VALUE= "'+newmsg+'" SIZE= '+ctrlwidth+' ></CENTER>');
document.write ('</FORM>');
var bannerID = null
rollmsg()
}
function rollmsg() {
NowMsg = document.Scrolltext.text.value
NowMsg = NowMsg.substring(1,NowMsg.length)+NowMsg.substring(0,1)
document.Scrolltext.text.value = NowMsg
bannerID = setTimeout("rollmsg()",100)//change the number 100 to represent the speed of the scroll. The larger the number the slower it moves
}
// -->
</script>


<script>
<!--
msg = " TEXT GOES HERE"
ctrlwidth = "100" //change this number to the length you would like the message box to be
text(msg,ctrlwidth);
// -->
</script>

当前文字颜色为黑色,应为白色。

3 个答案:

答案 0 :(得分:2)

您必须使用style属性,请尝试以下代码:

function rollmsg() {
  NowMsg = document.Scrolltext.text.value;
  NowMsg = NowMsg.substring(1,NowMsg.length)+NowMsg.substring(0,1);
  document.Scrolltext.text.value = NowMsg;
  document.Scrolltext.text.style.color ="white"; //use the style proprety here
  bannerID = setTimeout("rollmsg()",100)//change the number 100 to represent the speed of the  scroll. The larger the number the slower it moves
}

答案 1 :(得分:1)

理想情况下,您应该使用CSS。

body{
  color: #FFFFFF;
}

What is CSS? | W3C

答案 2 :(得分:0)

尝试使用以下代码

   var result = NowMsg.fontcolor("white");