我对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>
我的document.ready是(减去其中的其他功能)
$(document).ready(function () {
var validator = $('#FARInfo').kendoValidator();
});
我的按钮点击事件是
$('#SubmitFAR').on('click', function () {
var validator = $("#FARInfo").kendoValidator().data("kendoValidator");
if(validator.validate()){
SubmitFAR();
}
});
答案 0 :(得分:0)
您只需要var validator = $("#FARInfo").kendoValidator().data("kendoValidator");
一次。但这不是一个真正的问题。
我重建了您的来源,无法重现您的错误,对我来说,您所需的验证工作正常。也许你以错误的方式加载了脚本?