Javascript 如何为选择框中的选项添加背景图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11207223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add background image for options in a select box?
提问by Eli
Can anyone give me a cross-browser supported solution for this problem?
谁能给我一个跨浏览器支持的解决方案来解决这个问题?
采纳答案by Ahsan Rathod
You can use a custom jquery plugin like in this reference:
您可以使用自定义 jquery 插件,如本参考:
回答by Subhajit
HTML:- You can use inline style like below,
HTML:- 您可以使用如下所示的内联样式,
<select>
<option style="background-image:url(1stimage.gif);">1</option>
<option style="background-image:url(2ndimage.gif);">2</option>
<option style="background-image:url(3rdimage.gif);">3</option>
</select>
The above code would work in Firefox and Webkit browsers. For rest of the browsers you can use JQuery UI, please find the link below
上面的代码适用于 Firefox 和 Webkit 浏览器。对于其他浏览器,您可以使用 JQuery UI,请找到以下链接
http://docs.jquery.com/UI/Selectable
http://docs.jquery.com/UI/Selectable
EDIT: You can also try this http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx
编辑:你也可以试试这个http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx