默认选择选项为空白 [英] default select option as blank

查看:96
本文介绍了默认选择选项为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的要求,其中我需要在HTML中的下拉菜单中默认没有选择任何选项。然而,

我不能使用这个,

 < select> 
< option>< / option>
< option>选项1< / option>
< option>选项2< / option>
< option>选项3< / option>
< / select>

因为,为此我需要进行验证来处理第一个选项。任何人都可以帮助我实现这个目标,但实际上并不包括第一个选项作为选择标签的一部分吗?

解决方案

也许这会有帮助。 C $ C><选择>
<选项禁用选定值> - 选择一个选项 - < / option>
< option>选项1< / option>
< option>选项2< / option>
< option>选项3< / option>
< / select>

- 选择一个选项 - 意愿默认显示。但是,如果您选择了一个选项,您将无法将其选中。



您也可以通过添加一个空的选项来隐藏它

code>



< option style =display:none>



,所以它不会再出现在列表中。


I have a very weird requirement, wherein I am required to have no option selected by default in drop down menu in HTML. However,

I cannot use this,

<select>
    <option></option>
    <option>Option 1</option>
    <option>Option 2</option>
    <option>Option 3</option>
</select>

Because, for this I will have to do validation to handle the first option. Can anyone help me in achieving this target without actually including the first option as part of the select tag?

解决方案

Maybe this will be helpful

<select>
    <option disabled selected value> -- select an option -- </option>
    <option>Option 1</option>
    <option>Option 2</option>
    <option>Option 3</option>
</select>

-- select an option -- Will be displayed by default. But if you choose an option,you will not be able select it back.

You can also hide it using by adding an empty option

<option style="display:none">

so it won't show up in the list anymore.

这篇关于默认选择选项为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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