放置< span/>是否不好?< option/>内的标签标签,仅用于字符串操作而不是样式? [英] Is it bad to put <span /> tags inside <option /> tags, only for string manipulation not styling?

查看:53
本文介绍了放置< span/>是否不好?< option/>内的标签标签,仅用于字符串操作而不是样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对< 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 5spec :

内容模型:

  • 如果元素具有标签属性和值属性:无.
  • 如果元素具有标签属性,但没有值属性:文本.
  • 如果元素没有标签属性并且不是数据列表元素的子元素:文本不是元素间空格.
  • 如果元素没有标签属性,并且是数据列表元素的子元素:文本.

因此,根据上下文的不同,您可以在< 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)*>)

option元素不能有任何子元素.所以是的,这很糟糕.

An option element cannot have any child elements. So yes, it is bad.

这篇关于放置&lt; span/&gt;是否不好?&lt; option/&gt;内的标签标签,仅用于字符串操作而不是样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆