简体   繁体   English

jQuery 验证:未捕获的类型错误:$(...)."valid is not a function" with valid references/order

[英]jQuery validate: Uncaught TypeError: $(...)."valid is not a function" with valid references/order

I'm getting the error message "Uncaught TypeError: $(...).valid is not a function" when attempting to call...尝试调用时,我收到错误消息“Uncaught TypeError: $(...).valid is not a function”

javascript javascript

$('input[data-val=true]').on('blur', function() {
    $(this).valid();
});

HTML HTML

<div class="col-xs-12 col-sm-5" style="margin-left:4px">
            <input required="True" class="form-control" data-bind="value: battleModel.ReserveTroopCount" data-val="true" data-val-number="The field Troop reserve must be a number." data-val-range="Troop reserve must be between 0 and 1000." data-val-range-max="1000" data-val-range-min="0" data-val-required="Troop reserve is required." id="ReserveTroopCount" name="ReserveTroopCount" placeholder="Troop reserve..." tabindex="1" title="Enter the minimum troops you want to reserve after the battle" type="text" value="5">

            <span class="field-validation-valid" data-valmsg-for="ReserveTroopCount" data-valmsg-replace="true"></span>
        </div>

References参考

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/Content/bootstrap.css" rel="stylesheet" />
<script src="@(Url.Content("/Scripts/jquery-2.2.4.js"))" type="text/javascript"></script>
<script src="@(Url.Content("/Scripts/jquery.validate.js"))" type="text/javascript"></script>
<script src="@(Url.Content("/Scripts/jquery.validate.unobtrusive.js"))" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="~/Scripts/bootstrap-toolkit.js"></script>
@Scripts.Render("http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.4.2.js")
<script src="../../Scripts/knockout.mapping-latest.js" type="text/javascript"></script>
<script src="@(Url.Content("~/Scripts/RRCommon.js"))" type="text/javascript"></script>
<script src="@(Url.Content("~/Scripts/StrUtil.js"))" type="text/javascript"></script>
<script src="@(Url.Content("~/Scripts/RRRoll.js"))" type="text/javascript"></script>

My jquery files are local, but they are valid.我的 jquery 文件是本地的,但它们是有效的。 Just pulled them off of NuGet today.今天刚刚将它们从 NuGet 中删除。 I see all of my scripts loaded in the browser...我看到浏览器中加载了所有脚本...

Screenshot of browser dev tools displaying my script sources显示我的脚本源的浏览器开发工具的屏幕截图

What am I missing?我错过了什么? Everything I've seen online suggests either the script reference is missing or they're in the wrong order.我在网上看到的所有内容都表明脚本参考丢失或它们的顺序错误。 Not sure what else to do.不知道还能做什么。 The error suggests the referenced jquery files aren't getting loaded.该错误表明未加载引用的 jquery 文件。 I also tried online cdn references to the jquery files but got the same error.我还尝试了对 jquery 文件的在线 cdn 引用,但遇到了同样的错误。

In order to use the jQuery form validation plugin, you need to set it up on your form first.为了使用 jQuery 表单验证插件,您需要先在表单上进行设置。 The documentation gives a few examples of this, but basically you need to select the form and run the .validate() function.文档提供了一些示例,但基本上您需要选择表单并运行.validate()函数。

var form = $( "#myform" );
form.validate();

Obviously you don't have a form element, so this is something you will need to add.显然你没有表单元素,所以这是你需要添加的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM