HTML选择下拉列表 [英] HTML select dropdown list

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

问题描述

我想要使用select,option标签下拉列表......但是当它第一次出现时,我希望它有一个信息,例如请选择一个名称,然后用户单击下拉列表并从可用的选项中进行选择...我尝试将请选择一个名称作为选项,但用户将能够选择此...这不是我想要的。我需要使用JavaScript来获得这个功能吗?或者我需要做什么?

I want to have a drop down list using the select, option tag... but when it first appear I want it to have an information, such as "Please select a name" then the user clicks on the drop down list and selects from the available option... I tried to made the "Please select a name" as an option, but then the user will be able to select this... which is not what I want. Do I need to use javascript to have this feature or what do I need to do?

如果有jQuery的方式来做到这一点, p>

If there'a jquery way to do this, this would be much helpful

推荐答案

< option value => - 请选择一个名称 - < / option> 作为第一个选项,并使用JavaScript(和后端验证)来确保用户选择了空值以外的内容。

Have <option value="">- Please select a name -</option> as the first option and use JavaScript (and backend validation) to ensure the user has selected something other than an empty value.

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

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