我可以在選擇元素的選項中使用HTML標簽嗎?(復制)

[英]Can I use HTML tags in the options for select elements? [duplicate]


This question already has an answer here:

這個問題已經有了答案:

Is it possible for the options of an HTML select element to include HTML tags?

HTML select元素的選項中是否可能包含HTML標記?

For example, given the following code:

例如,給定以下代碼:

 <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>

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).

我希望這些選項可以在HTML中呈現。在這個應用程序中,我可以使用HTML、CSS、JavaScript(包括jQuery)。HTML本身是通過Django (django.form.fields.select)呈現的。

4 个解决方案

#1


53  

No, you can't do this. <option> tags cannot contain any other tags.

不,你不能這么做。 <選項> 標簽不能包含任何其他標簽。

#2


4  

No, but this: Styling HTML Select may help you and there a lof of detail and votes here:

不,但是這個:樣式HTML選擇可以幫助你和這里的細節和選票:

How to style a <select> dropdown with CSS only without JavaScript?

如何在不使用JavaScript的情況下使用CSS樣式化

#3


3  

No, you cannot.

不,你不能。

What you would do if you wanted this is use something like a floating div and position and display it using Css to look like a select. Then using javascipt clicks allow users to select.

如果你想這樣做,你可以使用浮動div和位置,然后用Css顯示它,使它看起來像一個選擇。然后使用javascipt點擊允許用戶選擇。

Something like this: Reinventing the dropdown

像這樣:重新發明下拉菜單

#4


0  

option tag does not allow any children other than text

選項標簽不允許除了文本之外的任何子元素

Here is a fiddle I created a few months ago that replaces a select element with a list dropdown, and updates the select for each selection made. Just hide select with css http://jsfiddle.net/6zcRk/

這是我幾個月前創建的一個小提琴,它用一個列表下拉列表替換一個select元素,並更新所做的每個選擇的select。只需隱藏select與css http://jsfiddle.net/6zcRk/。

The user in this thread then turned it into a plugin available on github( see link in thread)

然后,這個線程中的用戶將其轉換為github上的插件(參見線程中的鏈接)

Custom drop-down panel with jQuery

使用jQuery的自定義下拉面板。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/06/28/72557cbcf124ea8186503c166eb83015.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com