I've always provided a value="something"
for my option
elements within a select
element.
我总是为select元素中的选项元素提供一个value =“something”。
Like so
<select>
<option value="true">True</option>
</select>
Now that I have made one with countries, there is a lot of extraneous data in there. I'm pretty sure if I remember correctly, that Firefox will send the text between the tags if a value attribute is not present.
既然我已经与国家建立了一个,那里有很多无关的数据。我很确定如果我没记错,如果没有value属性,Firefox会在标签之间发送文本。
My question is, is this behaviour the norm? Can I rely on all browsers sending the innerHTML of the option element if the value attribute is omitted?
我的问题是,这种行为是常态吗?如果省略value属性,我可以依赖所有发送option元素的innerHTML的浏览器吗?
Thanks
2 个解决方案
#1
Yes, this will work in all browsers.
是的,这适用于所有浏览器。
正如规范所说:
OPTION Attribute definitions
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.value = cdata [CS]此属性指定控件的初始值。如果未设置此属性,则将初始值设置为OPTION元素的内容。
#2
Grabbed from W3C:
从W3C获取:
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.
value = cdata [CS]此属性指定控件的初始值。如果未设置此属性,则将初始值设置为OPTION元素的内容。
With this I'd think that every major standard compliant browser should take the 'value' attribute and if it's not present take the element
有了这个,我认为每个符合标准的主要浏览器都应该采用'value'属性,如果它不存在则采用该元素
#1
Yes, this will work in all browsers.
是的,这适用于所有浏览器。
正如规范所说:
OPTION Attribute definitions
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.value = cdata [CS]此属性指定控件的初始值。如果未设置此属性,则将初始值设置为OPTION元素的内容。
#2
Grabbed from W3C:
从W3C获取:
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.
value = cdata [CS]此属性指定控件的初始值。如果未设置此属性,则将初始值设置为OPTION元素的内容。
With this I'd think that every major standard compliant browser should take the 'value' attribute and if it's not present take the element
有了这个,我认为每个符合标准的主要浏览器都应该采用'value'属性,如果它不存在则采用该元素