问题描述
我的 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>
我可以在网络选项卡中看到该文件
我可以看到文件
但是validate() 函数仍然无法识别
任何想法,我错过了什么?
这是一个使用 EntityFrameWorkCore 在 asp.net mvc 中制作的项目
解决方法
从我看到的 here 来看,您需要在 $("#form") 返回的 jQuery 对象上应用验证函数,而不是在您获得的 HTML 节点上与 $("#form")[0].
你试过执行这个吗?
$("#form").validate();
,
首先,您需要确保在jqury.validate.js
和jquery-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)