Is it bad to put lt;span /gt; tags inside lt;option /gt; tags, only for string manipulation not styling?(放lt;span/gt;不好吗?lt;option/gt; 中的标签标签,仅用于字符串操作而不是样式?)
问题描述
我想将 <option/>
标记的文本内容分组.假设我有以下:<option>8:00(1小时)</option>
,时间模式8:00
可以修改,然后文字括号内的(1小时)
也可以修改.
I would like to make groups of the text content of an <option />
tag. Say I have the following: <option>8:00 (1 hour)</option>
, the time pattern 8:00
can be modified, then the text in parenthesis (1 hour)
can also be modified.
我正在考虑做类似的事情
I was thinking of doing something like
<option>
<span>8:00</span>
<span> (1 hour)</span>
</option>
将 <span/>
标签放在 <option/>
标签内是不是很糟糕,只用于字符串操作而不是样式?
Is it bad to put <span />
tags inside <option />
tags, only for string manipulation not styling?
推荐答案
来自 HTML 5 规范:
内容模型:
- 如果元素有标签属性和值属性:Nothing.
- 如果元素有标签属性但没有值属性:文本.
- 如果元素没有标签属性并且不是 datalist 元素的子元素:不是元素间空白的文本.
- 如果元素没有标签属性并且是 datalist 元素的子元素:文本.
因此,根据上下文,您可以在 <option>
中放入两件事 - 文本或根本不放入 - 您可能不会放入 <span>
或那里的任何其他元素.
So depending on context there are two things that you can put inside an <option>
— text or nothing at all — you may not put a <span>
or any other element there.
来自 HTML 4.01 规范:
From the HTML 4.01 spec:
<!ELEMENT OPTION - O (#PCDATA) -- selectable choice -->
(甚至 HTML 3.2 和 HTML 2 规范都说:<!ELEMENT OPTION - O (#PCDATA)*>
)
(Even the HTML 3.2 and HTML 2 specs say: <!ELEMENT OPTION - O (#PCDATA)*>
)
选项元素不能有任何子元素.所以是的,这很糟糕.
An option element cannot have any child elements. So yes, it is bad.
这篇关于放<span/>不好吗?<option/> 中的标签标签,仅用于字符串操作而不是样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:放<span/>不好吗?<option/> 中的标签标签,仅用于字符串操作而不是样式?


- 失败的 Canvas 360 jquery 插件 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01