Change option background color on hover?

寵の児 提交于 2019-12-23 13:08:49

问题


How can I change the background color when user hovers it ? I have tried this but it's not working.

<select>
<option>bmw</option>
<option>audi</option>
<option>mercedes</option>
</select>



$('option').hover(function(){
$(this).css("background-color","#FFFFCC");
}); 

回答1:


You cannot use option in this way. The best solution would be styling something similar with <ul> and <li> and interacting with JS.




回答2:


hover event can not be bound to an option tag. I'll update this post if I find the documentation or proof that says so. In my experience, this cannot be done.




回答3:


Since you already use jQuery, there is a pretty nice plugin - image-dropdown + demo from the makers.



来源:https://stackoverflow.com/questions/9651988/change-option-background-color-on-hover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!