如何动态改变颜色

Ahm*_*jad 1 html javascript colors dynamic

我想改变我的字幕颜色这里是Html代码

<marquee><div id="thakan">Thakaan ka Ant, Shakti Turant!!</div></marquee>
Run Code Online (Sandbox Code Playgroud)

这是javascript代码

<script language="javascript" type="text/javascript">
var col=0;
function changeMarqueeColor()
{
    if(col==0)
    {
        //document.getElementById("p2").style.color="blue";
        documrnt.getElementById("thakan").style.color="yello";
        col=1;
    }
    else
    {
        documrnt.getElementById("thakan").style.color="blue";
        col=0;
    }

}
 b=setInterval("changeMarqueeColor();",500);
</script>
Run Code Online (Sandbox Code Playgroud)

您也可以通过以下链接访问此链接:http://jsfiddle.net/W4tzf/

sab*_*bof 5

以下代码有效.正如其他人提到的那样,你拼错了document.另外,实现您想要的最简单的方法是使用setInterval和不带引号的函数名称.

var col=0;
function changeMarqueeColor() 
{
    if(col==0)
    {
        document.getElementById("thakan").style.color="red";
        col=1;
    }
    else
    {
        document.getElementById("thakan").style.color="blue";
        col=0;
    }
}
setInterval(changeMarqueeColor,500);
Run Code Online (Sandbox Code Playgroud)