将jQuery元素更改为div?

时间:2014-03-10 06:46:31

标签: javascript html

如何更改window.changeColour通话分区ID而非窗口中的窗口?感谢

window.changeColour = function(value) {
    switch(value) {
       case 'b':
          color = "#FF0000";
          break;
       case 'r':
          color = "#0000FF";
          break;
       case 'p':
          color = "#FF00FF";
          break;
    }
    document.body.style.backgroundColor = color;
}

以下是HTML:

<div id= "genre"> 
    <br><br> 
    <p> 
        <input type="radio" name="music" value="radio" onClick="changeColour('b')">Blues 
        <br> 
        <input type="radio" name="music" value="radio" onClick="changeColour('r')">Rock 
        <br> 
        <input type="radio" name="music" value="radio" onClick="changeColour('p')">Pop 
        <br>
    </p> 
</div>

1 个答案:

答案 0 :(得分:0)

如果你的意思是获得身份Division的元素,并改变它的颜色,这就是你得到的

DEMO

var div = document.getElementById("Division")
div.changeColour = function(value)
    {
    switch(value)
     {
        case 'b':
            color = "#FF0000";
        break;
        case 'r':
            color = "#0000FF";
        break;
        case 'p':
            color = "#FF00FF";
        break;
    }
div.style.backgroundColor = color;
}