gpt4 book ai didi

javascript - jQuery 验证 : Uncaught TypeError: $(. ..) ."valid is not a function"具有有效的引用/顺序

转载 作者:行者123 更新时间:2023-11-29 11:01:09 24 4
gpt4 key购买 nike

我在尝试调用...时收到错误消息“Uncaught TypeError: $(...).valid is not a function”

javascript

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

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>

引用资料

<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>

我的 jquery 文件是本地的,但它们是有效的。今天刚把它们从 NuGet 中拉出来。我看到我的所有脚本都已加载到浏览器中...

Screenshot of browser dev tools displaying my script sources

我错过了什么?我在网上看到的所有内容都表明缺少脚本引用或顺序错误。不知道还能做什么。该错误表明未加载引用的 jquery 文件。我还尝试了对 jquery 文件的在线 cdn 引用,但得到了同样的错误。

最佳答案

为了使用 jQuery 表单验证插件,您需要先在您的表单上进行设置。 documentation给出了几个例子,但基本上你需要选择表单并运行 .validate() 函数。

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

显然您没有表单元素,所以这是您需要添加的内容。

关于javascript - jQuery 验证 : Uncaught TypeError: $(. ..) ."valid is not a function"具有有效的引用/顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46800748/

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