<fontcolor="#669900"style="font-weight:bolder;letter-spacing:2px;"><scriptlanguage="JavaScript">
text="www.jb51.net";
color1="green";
color2="red";
speed=200;
i=0;
if(navigator.appName=="Netscape"){
}
else{
document.write("<spanid=a></span>");
}
functionchangeCharColor(){
if(navigator.appName=="Netscape"){
document.a.document.write("<fontcolor="+color1+">");
for(varj=0;j<text.length;j++){
if(j==i){
document.a.document.write("<fontcolor="+color2+">"+Text.charAt(i)+"</font>");
}
else{
document.a.document.write(text.charAt(j));
}
}
document.a.document.write('</font>');
document.a.document.close();
}
if(navigator.appName=="MicrosoftInternetExplorer"){
str="<fontcolor="+color1+">";
for(varj=0;j<text.length;j++){
if(j==i){
str+="<fontcolor="+color2+">"+text.charAt(i)+"</font>";
}
else{
str+=text.charAt(j);
}
}
str+="</font>";
a.innerHTML=str;
}
(i==text.length)?i=0:i++;
}
setInterval("changeCharColor()",speed);
//End-->
</script>
</font>
运行效果
text = "这里输入你要的文字 www.jb51.net"; color1 = "green"; color2 = "red"; speed = 200; i = 0; if (navigator.appName == "Netscape") { } else { document.write(""); } function changeCharColor() { if (navigator.appName == "Netscape") { document.a.document.write(""); for (var j = 0; j < text.length; j++) { if(j == i) { document.a.document.write("" + Text.charAt(i) + ""); } else { document.a.document.write(text.charAt(j)); } } document.a.document.write(''); document.a.document.close(); } if (navigator.appName == "Microsoft Internet Explorer") { str = ""; for (var j = 0; j < text.length; j++) { if( j == i) { str += "" + text.charAt(i) + ""; } else { str += text.charAt(j); } } str += ""; a.innerHTML = str; } (i == text.length) ? i=0 : i++; } setInterval("changeCharColor()", speed); // End -->
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]