开发者

Colored selected row in a dropdown list

开发者 https://www.devze.com 2023-04-04 23:58 出处:网络
Is there a way to color a selected row from a dropdown list? jQuery/JavaScript is wel开发者_JAVA技巧comed as wellvar select = document.getElementById(\"mySelectBox\");

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

精彩评论

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