【发布时间】:2018-11-14 13:32:17
【问题描述】:
display: none; 在 html 的选项标签内不起作用。为什么?
html
<select>
<option data-color="green"> Option 1
<div style="display: none;"> hiddenText </div>
</option>
<option data-color="red"> Option 1
</option>
</select>
我将 style="display: none;" 应用于 textContent 等于 hiddenText 的节点。所以,我预计不会看到hiddenText,但我仍然看到它。我在这里错过了什么?
谢谢。
如果我们将 div inside 选项更改为 span,它仍然不起作用。
【问题讨论】:
-
我认为不可能在
option标签内添加div。 MDN quote: Permitted content: Text, possibly with escaped characters (like é) -
@enxaneta,谢谢。有什么建议我该如何克服这个问题?
-
我以为我可以用伪元素来做到这一点,但它也不起作用。请解释为什么需要在选项中隐藏文本。也许有一个解决方法。
标签: html css select option display