2014-11-21 54 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