开发者

Colored selected row in a dropdown list

Is there a way to color a selected row from a dropdown list? jQuery/JavaScript is wel开发者_JAVA技巧comed as well


var select = document.getElementById("mySelectBox");
var oldSelectedIndex = select.selectedIndex;
select.addEventListener("change", function(){
    select.options[oldSelectedIndex].style.cssText = "";//or .className = ""
    select.options[oldSelectedIndex=select.selectedIndex].style.cssText = "color:red;";
}, true);


You're also free to use the :selected pseudo-class in pure CSS.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜