选择选项值可以是不同的类型? [英] Can the select option value be of different types?

查看:75
本文介绍了选择选项值可以是不同的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



示例

 

我想知道选择选项值的最佳做法。 < select name =select>
< option value =0-9>样本< / option>
< option value =a-z>样本< / option>

我在这里有点困惑。是否选择值与输入文本 textarea

解决方案

可以在option元素的value属性中设置的数据类型没有限制。当然,HTML中具有特殊含义的字符需要由适当的实体(& )来表示& amp; (尽管问题中的那个符合规则的后面跟一个空格字符的例外))。

该属性被定义为包含CDATA :

 <!ELEMENT OPTION  -  O(#PCDATA) - 可选择的选项 - > 
<!ATTLIST OPTION
%attrs; - %coreattrs,%i18n,%events - 选择
(选择)#IMPLIED
禁用(禁用)#IMPLIED - 在此上下文中不可用 -
标签%Text; #IMPLIED - 用于分层菜单 -
值CDATA #IMPLIED - 默认为元素内容 -
>

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


CDATA是
文档字符集中的一系列字符,可能
包含字符实体。用户
代理应该如下解释属性
的值:
$ b


  • 用字符替换字符实体,

  • 忽略换行符

  • 用一个空格替换每个回车符或制表符。


用户代理可能会忽略CDATA
属性值(例如,myval
可能被解释为myval)中的前导和
尾随空白。
作者不应该使用前导或后缀为白色的
空间来声明属性
值。

对于CDATA $ b $的某些HTML 4属性b属性值,则规范
会对
不能由DTD表示的属性的合法值的集合
施加进一步限制。




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



规范没有对选项元素的value属性施加额外的限制。


I want to know what is good practice for select option values.

Example

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

I'm a little bit confused here. Is the select value same like input text and textarea

解决方案

There are no limits real to the type of data that can be set in the value attribute of the option element. Characters with special meaning in HTML do, of course, need to be represented by the appropriate entities (& as &amp; for example (although the one in the question meets the "followed by a space character" exception to the rule)).

The attribute is defined as containing 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

The specification doesn't impose additional limits for the option element's value attribute.

这篇关于选择选项值可以是不同的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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