Changing color of a row in dropdown list
Is it possible to change "selector" color 开发者_开发技巧in drop-down list?
<select name="select" style="background-color: #ff0000">
<option style="background-color: #ff0000" value="1">Red</option>
<option style="background-color: #ffffff" value="2">Green</option>
<option style="background-color: #0000ff" value="3">Blue</option>
</select>
I tried in above style but it didn't worked. I know with JavaScript getting document.getElementById('text').style.color='red'
can set the color.
But is it possible in HTML to set the colors?
To preserve the background color of the selected item (which I believe is what you're after) add the following onchange
code:
<select name="select" style="background-color: #ff0000" onchange="this.style.backgroundColor = this.options[this.selectedIndex].style.backgroundColor;">
Live test case: http://jsfiddle.net/yahavbr/LD8Dx/
its work correctly in many browsers. I didnt see any problem with this HTML.
It works for me in Google Chrome and Mozilla Firefox.
Edit: also works in IE6
精彩评论