2014-11-21 26 views
0

我是新来的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> 

当前的文本颜色是黑色的,它应该是白色。

回答

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 
} 
+0

它工作。谢谢。 – 2014-11-21 10:07:33

+0

很高兴它有帮助,只要记住你必须使用'.style'来访问元素样式。 – 2014-11-21 10:09:25

+0

会做。你有没有机会知道如何从左到右滚动?与其当前滚动方向相反 – 2014-11-21 11:47:35

0

尝试用下面的代码

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

我在哪里需要的地方呢? – 2014-11-21 09:58:58

+0

在代码 的下面添加代码document.Scrolltext.text.value = NowMsg NowMsg.fontcolor(“white”); – nikita 2014-11-21 09:59:53

+0

我试过了,但它没有奏效。不管怎样,谢谢你。 – 2014-11-21 10:07:57