我对div的内容进行了验证,它们是一堆输入和下拉列表,我根本无法使验证工作。在 document.ready 上,我水化下拉列表并从那里开始,但是当我单击我的提交按钮时,验证不会触发,我也没有收到任何控制台错误
我的标记是
<div class="container">
<div class="form-horizontal">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="col-md-12">
<div id="FARInfo">
<div class="row">
<div class="form-group">
<center><h1 style="font-weight:bold; color:#1d5f86">Create Alert</h1></center>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-4">
<input id="ddState" class="form-control max-size" name="state" required validationMessage="Required" />
<span class="k-invalid-msg" data-for="state"></span>
</div>
<div class="col-md-8">
<input id="ddCounty" class="form-control max-size topMargin" name="county" required validationMessage="Required" />
<span class="k-invalid-msg" data-for="county"></span>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<input id="ddDepartment" class="form-control max-size" name="department" required validationMessage="Required" />
<span class="k-invalid-msg" data-for="department"></span>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<input id="ddDistrict" class="form-control max-size" name="district" required validationMessage="Required" />
<span class="k-invalid-msg" data-for="district"></span>
</div>
</div>
</div><!-- End District -->
<div class="row">
<div class="form-group">
<div class="col-md-12">
<input type="text" id="txtReporter" class="form-control" name="reporter" placeholder="Reporter" required validationMessage="Required" style="max-width:100%;" />
<span class="k-invalid-msg" data-for="reporter"></span>
</div>
</div>
</div><!-- End Reporting Party -->
<div class="row">
<div class="form-group">
<div class="col-md-12">
<input type="text" id="txtAddress" class="form-control" name="address" placeholder="Address" required validationMessage="Required" style="max-width:100%;" />
<span class="k-invalid-msg" data-for="address"></span>
</div>
</div>
</div><!-- End Address -->
<div class="row">
<div class="form-group">
<div id="Cancel" class="col-md-6">
<div class="form-control" id="CancelFAR" style="background-color:#1D5F86; color:white; font-weight:bold">
<center><a href="@Url.Content("~/Home/Index")" style="text-decoration:none; color:white;">Cancel</a></center>
</div>
</div>
<div class="col-md-6">
<button class="btn btn-block btn-success" id="SubmitFAR">
Submit
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3"></div>
</div>
</div>
My Document.ready 是(减去其中的其他函数)
$(document).ready(function () {
var validator = $('#FARInfo').kendoValidator();
});
我的按钮单击事件是
$('#SubmitFAR').on('click', function () {
var validator = $("#FARInfo").kendoValidator().data("kendoValidator");
if(validator.validate()){
SubmitFAR();
}
});
您只需要一次var validator = $("#FARInfo").kendoValidator().data("kendoValidator");
。但这并不是一个真正的问题。
我重建了您的源代码,无法重现您的错误,对我来说,您所需的验证器工作。也许您以错误的方式加载了脚本?
看一看:https://dojo.telerik.com/OyUFu