html – select选项的值可以是不同的类型吗?

前端之家收集整理的这篇文章主要介绍了html – select选项的值可以是不同的类型吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道什么是选择选项值的好习惯.

<select name="select">
  <option value="0-9">Sample</option>
  <option value="a-z">Sample</option>
  <option value="this is sample value">Sample</option>
  <option value="this-is-sample-value">Sample</option>
  <option value="this_is_sample_value">Sample</option>
  <option value="this & is | sample ** value">Sample</option>
</select>

我在这里有点困惑选择值与输入文本和textarea一样

解决方法

对于可以在option元素的value属性中设置的数据类型,实际上没有任何限制.在HTML中具有特殊意义的字符当然需要由适当的实体(例如& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; ).

属性定义为包含CDATA:

<!ELEMENT OPTION - O (#PCDATA)         -- selectable choice -->
<!ATTLIST OPTION
  %attrs;                              -- %coreattrs,%i18n,%events --
  selected    (selected)     #IMPLIED
  disabled    (disabled)     #IMPLIED  -- unavailable in this context --
  label       %Text;         #IMPLIED  -- for use in hierarchical menus --
  value       CDATA          #IMPLIED  -- defaults to element content --
  >

http://www.w3.org/TR/html4/interact/forms.html#h-17.6

CDATA is a sequence of characters from
the document character set and may
include character entities. User
agents should interpret attribute
values as follows:

  • Replace character entities with characters,
  • Ignore line Feeds,
  • Replace each carriage return or tab with a single space.

User agents may ignore leading and
trailing white space in CDATA
attribute values (e.g.,” myval ”
may be interpreted as “myval”).
Authors should not declare attribute
values with leading or trailing white
space.

For some HTML 4 attributes with CDATA
attribute values,the specification
imposes further constraints on the set
of legal values for the attribute that
may not be expressed by the DTD.

http://www.w3.org/TR/html4/types.html#type-cdata

该规范不对option元素的value属性强加额外的限制.

原文链接:https://www.f2er.com/html/224458.html

猜你在找的HTML相关文章