使用选项标记添加图片 [英] Adding images with option tag

查看:85
本文介绍了使用选项标记添加图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表。我想添加图像与它。我尝试添加 img 标记在tha 选项标签...但仍然的图像不显示。
如何使用选项标签?

I have a drop down list. I want to add images along with it. I tried adding img tag inside tha option tag... But still the images are not getting displayed. How do I do it using option tag?

推荐答案

这是不可能的,因为只有 < option> 支持文本

It's not possible, as <option> only supports text.

您可能必须使用复杂的HTML / CSS / JavaScript滚动您自己的下拉控件。

You may have to roll your own drop-down control using complex HTML/CSS/JavaScript. How to do it may or may not be within the scope of your question.

或者,您也可以使用不重复的 background-image 并对文本应用一些填充以实现类似的效果。但是如果每个< option> 都有一个唯一的图像,你的代码将被污染的 style 属性为每个< option> 。如果你不介意,这很好。否则,自己滚动自己。

Alternatively, you may use a non-repeating background-image and apply some padding on the text to achieve a similar effect. But if each <option> is to have a unique image, your code is going to be polluted with a style attribute for every single <option>. If you don't mind that, it's fine. Otherwise, roll your own somehow.

这篇关于使用选项标记添加图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆