Change option background color on hover?

2019-06-25 23:41发布

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");
}); 

3条回答
男人必须洒脱
2楼-- · 2019-06-26 00:22

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

查看更多
男人必须洒脱
3楼-- · 2019-06-26 00:23

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.

查看更多
叼着烟拽天下
4楼-- · 2019-06-26 00:25

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

查看更多
登录 后发表回答