2011-05-19 150 views
5

我只是想知道什麼有效的字符可以作爲一個<option>有效字符

值即是這有效嗎?

<select> 
    <option value='0dbl,2sgl'>0 Double and 2 Singles</option> 
    <option value='1dbl,0sgl'>1 Double and 0 Singles</option> 
</select> 

回答

10

是的,這是完全有效的。 See the specification:它說的value的內容應該是CDATA,其中幾乎一切有效,有以下注意事項:

  • 替換字符的字符實體,
  • 忽略換行符,
  • 替換每個車廂返回或帶有一個空格的選項卡。
+0

太棒了。謝謝。 – silent1mezzo 2011-05-19 20:01:06

3

對於HTML4:

OPTION Attribute definitions 

selected [CI] 
    When set, this boolean attribute specifies that this option is pre-selected. 
value = cdata [CS] 
    This attribute specifies the initial value of the control. If this attribute is not set, the initial value is set to the contents of the OPTION element. 
label = text [CS] 
    This attribute allows authors to specify a shorter label for an option than the content of the OPTION element. When specified, user agents should use the value of this attribute rather than the content of the OPTION element as the option label. 

來源:http://www.w3.org/TR/html401/interact/forms.html#h-17.6

所以我們去CDATA的定義:

CDATA是一個字符從 文件序列字符集並可能包含字符entiti ES。用戶 劑應如下解釋屬性 值:

  • 與字符替換字符實體,
  • 忽略換行符,
  • 替換爲單個空格每個回車或標籤。 用戶代理可能會忽略CDATA屬性值中的前導和尾隨空白(例如,「myval」可能會被解釋爲「myval」)。作者不應該使用前導空白或尾隨空白聲明屬性值。

對於CDATA 屬性值的一些HTML 4個屬性,說明書 強加合法值的設定 爲屬性進一步約束 可以不被DTD來表示。

來源:http://www.w3.org/TR/html401/types.html#type-cdata

由於沒有約束指出的,value有效的內容必須正確轉義實體,正確定義的實體,並且是文檔的編碼範圍之內。