开发者

Div background change to 12 different colours

I have this code to change the background colour of a div tag upon hovering over another image. However, it only flips one div tag between two background colours. I need to have 12 images change one div tag to 12 different colours only (one colour per image as opposed to this which switches to one colour on the first hover and another colour on the second). I am really new to this so any help would be greatly appreciated.

Code:

    function changeBackgroundColor(objDivID)
    {
        var backColor = new String();

  开发者_StackOverflow      backColor = document.getElementById(objDivID).style.backgroundColor;

        // IE works with hex code of color e.g.: #eeeeee
        // Firefox works with rgb color code e.g.: rgb(238, 238, 238)
        // Thats why both types are used in If-condition below
        if(backColor.toLowerCase()=='#eeeeee' || backColor.toLowerCase()=='rgb(238, 238,     238)')
        {
            document.getElementById(objDivID).style.backgroundColor = '#c0c0c0';
        }
        else
        {
            document.getElementById(objDivID).style.backgroundColor = '#eeeeee';
        }
    }


there is spaces misspelled in the if statement. the rgb() spaces separators syntax must be the same as browser's syntax

replace if statement with the following:

if(backColor.toLowerCase()=='#eeeeee' || backColor.toLowerCase()=='rgb(238, 238, 238)')

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜