admin管理员组文章数量:1289527
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?
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?
Share Improve this question edited Feb 8, 2011 at 8:42 Brock Adams 93.6k23 gold badges241 silver badges305 bronze badges asked Feb 8, 2011 at 7:20 JudyJudy 1,5539 gold badges27 silver badges41 bronze badges 1- 1 AFAIK there isn't a cross patible way of acplishing this without the aid of Javascript. i.e. Styling each option value. – Russell Dias Commented Feb 8, 2011 at 8:14
3 Answers
Reset to default 6To 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/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
本文标签: javascriptChanging color of a row in dropdown listStack Overflow
版权声明:本文标题:javascript - Changing color of a row in dropdown list - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741397574a2376469.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论