0

我对 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();

}

});

4

1 回答 1

0

var validator = $("#FARInfo").kendoValidator().data("kendoValidator");只需要一次。但这并不是一个真正的问题。

我重建了您的源代码并且无法重现您的错误,对我来说,您的所需验证器可以工作。也许您以错误的方式加载脚本?

看看:https ://dojo.telerik.com/OyUFu

于 2018-01-26T09:56:59.487 回答