验证选择框 [英] Validate select box

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

问题描述

我使用jQuery插件验证来验证表单。我有一个如下所示的选择列表:

I'm using the jQuery plugin Validation to validate a form. I have a select list looking like this:

<select id="select">
<option value="">Choose an option</option>
<option value="option1">Option1</option>
<option value="option2">Option2</option>
<option value="option3">Option3</option>
</select>

现在,我想确保用户选择除Choose an option之外的任何内容(即默认的)。因此,如果您选择第一个选项,它将不会验证。如何做到这一点?

Now, I want to make sure that the user selects anything but "Choose an option" (which is the default one). So that it won't validate if you choose the first option. How can this be done?

推荐答案

只需添加一个需要的类到选择

Just add a class of required to the select

<select id="select" class="required">

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

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