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.
精彩评论