微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

验证未检测为函数

如何解决验证未检测为函数

我的 html 页头有

<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>

我可以在网络选项卡中看到该文件

enter image description here

我可以看到文件

enter image description here

但是validate() 函数仍然无法识别

enter image description here

任何想法,我错过了什么?

这是一个使用 EntityFrameWorkCore 在 asp.net mvc 中制作的项目

解决方法

从我看到的 here 来看,您需要在 $("#form") 返回的 jQuery 对象上应用验证函数,而不是在您获得的 HTML 节点上与 $("#form")[0].

你试过执行这个吗?

$("#form").validate();
,

首先,您需要确保在jqury.validate.jsjquery-xxx.js之后加载jquery-xxx.min.js。例如,如果您看到加载顺序是jquery-xxx.min.js,{{1 }},jqury.validate.js,你会得到错误jquery-xxx.js

你可以放

$().validate is not a function

在 Shared/_layout.cshtml 中,如下所示:

<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>

并且不需要将脚本添加到您使用它的页面中。

其次,你需要使用like

 @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
    @RenderSection("scripts",required: false)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。