我可以在选择元素的选项中使用HTML标记吗?
问题描述:
HTML选择元素的选项是否可以包含HTML标签?
Is it possible for the options of an HTML select element to include HTML tags?
例如,给定以下代码:
<select>
<option value="one"><b>one is bold</b></option>
<option value="two">two has some <span style='color:red;'>red</span> text</option>
<option value="three">three is just normal</option>
</select>
我想要的选项实际上在HTML中呈现。在这个应用程序中,我可以使用HTML,CSS,JavaScript(包括jQuery)。而且HTML本身是通过Django(django.form.fields.select)渲染的。
I would like the options to actually render in HTML. In this application I can play with HTML, CSS, JavaScript (including jQuery). And the HTML itself is being rendered via Django (django.form.fields.select).
答
不,你不能做这个。 < option>
标签不能包含任何其他标签。
No, you can't do this. <option>
tags cannot contain any other tags.