html select元素,默认不在选项中 [英] html select element with default not in the options

查看:150
本文介绍了html select元素,默认不在选项中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
< select>占位符

Possible Duplicate:
<select> placeholder

我想做这样的事情:

<select>
    <option selected="selected">Choose option</option>
    <option>Option 1</option>
    <option>Option 2</option>
    <option>Option 3</option>
    <option>Option 4</option>
</select>

这是 jsfiddle.

现在,我希望选择的第一个选项的内容选择选项"在下拉菜单中不可见.如果可以使用select元素,或者我应该做自定义的事情,我该怎么做. 预先感谢.

now I want the first option the selected one with the content "Choose option" to not be visible in the dropdown. how can i do that, if that's possible with a select element or should i do a custom thing. Thanks in advance.

推荐答案

您可以在打开列表后立即删除所选元素:

You could remove the selected element as soon as you open the list:

$('select').click(function () {
  $('option[selected="selected"]', this).remove();
});

我不知道任何本机HTML/HTML5解决方案.

I am not aware of any native HTML/HTML5 solution.

这篇关于html select元素,默认不在选项中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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