什么值可以出现在

什么值可以出现在

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

问题描述

我有类似以下的标记:

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

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

解决方案

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

在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):

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.

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

08-15 12:00