您可以在< option>元件? [英] Can you have multiple lines in an <option> element?
问题描述
在< option>
元素中是否有多行的方法?
Is there a way to have multiple lines in an <option>
element?
像这样:
-------------------------
| Normal <option> element |
-------------------------
| <option> element broken |
| onto two lines |
-------------------------
| Normal <option> element |
-------------------------
有没有HTML / CSS方法,或者我应该使用JavaScript吗?
Is there any HTML/CSS approach, or should I use JavaScript?
推荐答案
元素中显示HTML标签的情况。< option>< / option>
据我所知,浏览器在这方面的行为非常不同(Firefox显示甚至图像,其他浏览器忽略大多数或所有标签),没有跨浏览器解决方案。您可能需要使用JavaScript和不同的标记来模拟它。
It's a particular case of displaying HTML tags inside an <option></option>
element. As far as I know, browsers behave very differently in this area (Firefox displays even images, other browsers ignore most or all tags) and there isn't a cross-browser solution. You'll probably need to emulate it with JavaScript and a different markup.
在 http://www.w3.org/TR/2011/WD-html-markup-20110113/option.html 他们说:
允许的内容:正常字符
数据
Permitted contents: normal character data
...定义在 http://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#normal-character-数据
该规范很难理解,像往常一样,但我明白你不能插入文字<
(即一个HTML标签如< br>
)。我找不到它在哪里定义与空白行为,但大多数浏览器似乎崩溃了。
The spec is hard to understand, as usual, but I understand that you cannot insert a literal <
(i.e., an HTML tag such as <br>
). I cannot find where it defines the behaviour with blank space but most browsers appear to collapse it.
这篇关于您可以在< option>元件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!