[英]Multiple Dropdown validation in jQuery is not working
我需要檢查所有下拉框都有一個選定的值,但是下面的 jQuery 驗證了唯一的第一個下拉列表。 我該如何解決? 請幫我。
MVC html
<% foreach (var item in Model.list)
{ %>
<select name="GroupSelect" style=" width : 100px;" class="GroupSelect">
<option>--SELECT--</option>
<option>Ball</option>
<option>Bat</option>
</select>
<% } %>
<input type="submit" id="details" />
我的 jQuery:
$('#details').click(function () {
if ($('.GroupSelect').val() == "--SELECT--") {
$('#error').attr('class', 'errorMessage');
$('#error').text("Some Club Id Group Name is Missing Please Select the Group Name");
return false;
}
});
您需要檢查each()
這樣做:
$('#details').click(function () {
$('.GroupSelect').each(function() {
if($(this).val() === "--SELECT--") {
$('#error').attr('class', 'errorMessage');
$('#error').text("Some Club Id Group Name is Missing Please Select the Group Name");
return false;
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.