将optgroup标签显示为初始选项 [英] Display optgroup label as initial option

查看:477
本文介绍了将optgroup标签显示为初始选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在选择下拉列表中显示optgroup的标签作为第一个选项?

Is it possible to show the label of an optgroup in a select dropdown as the first option?

这是否有意义?或者有更好的方法吗?

Does this make sense? Or is there a better way to do it?

我基本上需要一个第一个标签,显示像选择价格,这是不能直接选择,但显示当你展开

I basically need a first label that shows like Select Price and that isn't directly selectable, but shows when you expand the select menu like an optgroup label does.

推荐答案

您可以使用标准的选项元素,只需指定 disabled 属性:

You can use a standard option element and simply specify the disabled attribute:

<select>
    <option disabled="disabled" selected="selected">Select Price</option>
    <optgroup label="Gold">
        <option>5.00</option>
        <option>10.00</option>
    </optgroup>
</select>

查看此 jsFiddle demo

这篇关于将optgroup标签显示为初始选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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