空白HTML SELECT在下拉列表中没有空白项 [英] Blank HTML SELECT without blank item in dropdown list

查看:252
本文介绍了空白HTML SELECT在下拉列表中没有空白项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我写:

  

如何实现subj?



<形式>
< select>
< option value =0> aaaa< / option>
< option value =1> bbbb< / option>
< / select>
< / form>

然后默认选择的项目是aaaa



当我写:

 < form> 
< select>
< option value =>< / option>
< option value =0> aaaa< / option>
< option value =1> bbbb< / option>
< / select>
< / form>

然后默认选择的项目为空,但此空白项目呈现在下拉列表中。



我如何使用隐藏在下拉列表中的默认空白值来实现SELECT标签?

解决方案

只需使用禁用和/或隐藏的属性:

 <选项已禁用隐藏样式='显示:无'值=' >< /选项> 




  • selected 将此选项设为默认选项。

  • 已禁用使此选项无法触发。

  • style ='display:none'使此选项不会在旧版浏览器中显示。请参阅:我可以使用文档的隐藏属性。

  • 隐藏使此选项不显示在下拉列表中。


How implement subj?

when i write:

<form>
  <select>
     <option value="0">aaaa</option>
     <option value="1">bbbb</option>
  </select>
</form>

then default selected item is "aaaa"

when i write:

<form>
  <select>
     <option value=""></option>
     <option value="0">aaaa</option>
     <option value="1">bbbb</option>
  </select>
</form>

then default selected item is blank, but this blank item presents in drop down.

how i can implement SELECT tag with default blank value that hidden in dropdown list?

解决方案

Just use disabled and/or hidden attributes:

<option selected disabled hidden style='display: none' value=''></option>

  • selected makes this option the default one.
  • disabled makes this option unclickable.
  • style='display: none' makes this option not displayed in older browsers. See: Can I Use documentation for hidden attribute.
  • hidden makes this option to don't be displayed in the drop-down list.

这篇关于空白HTML SELECT在下拉列表中没有空白项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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