使用 jQuery.validate 检查 3 个下拉列表是否都选择了非默认选项
我想使用 jQuery.validate() 插件来检查用户是否从 3 个下拉列表中选择了一个选项 - 其出生日期的日、月和年。我不需要验证实际日期,只要他们选择一些内容即可。我只想显示一条验证错误消息“请提供您的出生日期”。
您可以想象标记是什么样子,但无论如何它都是这样的:
<div class="dropdown">
<select id="day" class="styled" name="day">
<option value="">--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
[ etc... ]
</select>
</div>
<div class="dropdown">
<select id="month" class="styled" name="month">
<option value="">--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
[ etc... ]
</select>
</div>
<div class="dropdown">
<select id="year" class="styled" name="year">
<option value="">--</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
[ etc... ]
</select>
</div>
I want to use the jQuery.validate() plugin to check that the user has chosen an option from 3 dropdown lists - day, month and year for their DOB. I don't need to validate the actual date, just as long as they choose something. I just want the one validation error message to be displayed to read "Please provide your date of birth".
You can imagine what the markup looks like, but here it is anyway:
<div class="dropdown">
<select id="day" class="styled" name="day">
<option value="">--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
[ etc... ]
</select>
</div>
<div class="dropdown">
<select id="month" class="styled" name="month">
<option value="">--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
[ etc... ]
</select>
</div>
<div class="dropdown">
<select id="year" class="styled" name="year">
<option value="">--</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
[ etc... ]
</select>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我为出生日期选择创建了三个下拉菜单,并且天数根据年份和月份选择动态变化。 http://jsfiddle.net/ravitejagunda/FH4VB/10/。 Fiddle 有下拉菜单的完整代码
I created three dropdowns for Date of Birth selection and number of days changes dynamically based on the year and month selection. http://jsfiddle.net/ravitejagunda/FH4VB/10/. Fiddle has the complete code for the dropdowns
严格来说不是 JQuery,但我在 JavaScript 中做了一个函数,它配置表单下拉列表以适应给定月/年组合的天数,它期望下拉列表将第一个条目作为
描述
Not strictly JQuery, but i did a function in JavaScript, which configures the form drop downs to suit the number of days for a given month/year combination, it expects the drop downs to have the first entry as a description
The Function
在选择中添加“必需”类。看看这个 fiddle
这是你的js
Add a "required" class in the selects. Check out this fiddle
This is your js