什么值可以出现在“选定” “选项”的属性标签? [英] What values can appear in the "selected" attribute of the "option" tag?

查看:89
本文介绍了什么值可以出现在“选定” “选项”的属性标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似以下的标记:

 < select> 
< option selected =selected> Apple< / option>
< option selected =>橙色< /选项>
< / select>

在这种情况下,橙色显示为选定的项目。我期望将选中的属性设置为空白将撤销其效果。有没有一种方法来写这个,而不只是离开属性?

解决方案

不同的浏览器可能会以不同的方式处理此属性。根据MSDN文档(针对Internet Explorer):


要选择HTML中的项目,不需要
来设置
SELECTED属性的值为true。仅仅
存在的SELECTED属性将
的值设置为true。


在firefox和Safari中, work:

 < option selected ='false'/> 

通过查看HTML4的官方WC3标准,我可以看出支持的情况只是:

 < option selected ='selected'/> 

您需要选择性地发射属性,或者使用javascript来控制最初选择的项目。

I have some markup similar to the following:

<select>
  <option selected="selected">Apple</option>
  <option selected="">Orange</option>
</select>

In this case, "Orange" shows as the selected item. I would have expected making the selected attribute blank would undo its effects. Is there a way to write this without simply leaving the attribute out?

解决方案

Different browser may treat this attribute differently. According to the MSDN documentation (for Internet Explorer):

To select an item in HTML, it is not necessary to set the value of the SELECTED attribute to true. The mere presence of the SELECTED attribute set its value to true.

In firefox and Safari this does work:

<option selected='false' />

From what I can tell by looking at the official WC3 standard for HTML4, the supported case is only:

<option selected='selected' />

You will either need to selectively emit the attribute, or use javascript to control which item is initially selected.

这篇关于什么值可以出现在“选定” “选项”的属性标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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