gpt4 book ai didi

javascript - jQuery 验证下拉列表

转载 作者:行者123 更新时间:2023-11-28 05:21:37 25 4
gpt4 key购买 nike

我遇到了一个奇怪的问题。尝试使用 jQuery 验证来验证表单上的下拉/选择列表,但它无法验证。不知道为什么,我仔细检查了是否有任何拼写错误或任何语法错误,但没有。下面是我的代码的副本。

感谢一百万!

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="~/Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script>
$(function () {
//datepicker script
$( "#datepicker" ).datepicker({
altField: $('#dateHdn'),
dateFormat: "MM-dd-yy"
}); //end of datepicker script

//configure validation here
$("#addform").validate({
rules: {
invacc: { required:true },
lvlstat: { required: true }

},
messages: {
invacc: "please insert a value",
lvlstat: "Please choose a status"
}
})// end of validate script

//dropdown script
$("#lvlstat").selectmenu({
});//end of dropdown script});

</script>
</head>

<body>
<form id="addform" method="post" enctype="multipart/form-data" action="">
<fieldset>
<legend>Add Required Values</legend>
<p>
<label for="invacc">Inventory Accuracy: </label>
<input type="text" name="invacc" />
</p>
<p>
<label for="lti">LTI: </label>
<input type="text" name="lti" />
</p>
<p>
<label for="overtime">Overtime: </label>
<input type="text" name="overtime" />
</p>
<p>
<label for="datetime">Date: </label>
<input type="text" name="dtval" id="datepicker" />
</p>
<p>
<label for="lvlstat">Status: </label>
<select id="lvlstat" name="lvlstat">
<option value="">Choose an Option</option>
<option value="1">Certified</option>
<option value="2">Learner</option>
<option value="3">Rookie</option>
</select>
</p>
<p><label for="FileUpload">Image Upload: </label>
@FileUpload.GetHtml(
initialNumberOfFiles: 1,
allowMoreFilesToBeAdded: false,
includeFormTag: false,
uploadText: "Upload")
</p>
<p><input type="submit" name="buttonSubmit" value="Add" /></p>
<p><a href="~/main">Return to main page</a></p>

</fieldset>
</form>
</body>

最佳答案

添加这个

$("input[name='buttonSubmit']").click(
function(){
if($('#lvlstat').val() == ''){
alert('dropdown validationg failed');
return false;
}
});

Fiddle

关于javascript - jQuery 验证下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40502613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com