jQuery 未捕获的类型错误:无法设置未定义的属性“unobtrusive”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7911439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: Cannot set property 'unobtrusive' of undefined
提问by 010110110101
I am getting this error in the Chrome JScript debugger. It happened when I switched to the Microsoft CDNs for the scripts below.
我在 Chrome JScript 调试器中收到此错误。当我为下面的脚本切换到 Microsoft CDN 时发生了这种情况。
I'm not sure how to work around this save, not using the CDNs anymore.
我不确定如何解决此保存问题,不再使用 CDN。
jquery.validate.unobtrusive.min.js:5 Uncaught TypeError: Cannot set property 'unobtrusive' of undefined
jquery.validate.unobtrusive.min.js:5 Uncaught TypeError:无法设置未定义的属性“unobtrusive”
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/start/jquery-ui.css" rel='stylesheet' type='text/css'>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-1.7-development-only.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.11/jquery-ui.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmplPlus.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js"></script>
回答by StuartQ
Another reason this error can occur is if you load the unobtrusive script before jquery.validate.
可能发生此错误的另一个原因是,如果您在 jquery.validate 之前加载不显眼的脚本。
So,
所以,
<script src="/scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
is OK, but:
可以,但是:
<script src="/scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="/scripts/jquery.validate.min.js" type="text/javascript"></script>
will give the "Cannot set property 'unobtrusive' of undefined" error.
将给出“无法设置未定义的属性 'unobtrusive'”错误。
回答by 010110110101
Found it. I was missing two lines:
找到了。我错过了两行:
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/additional-methods.min.js"></script>
I learned this by reading this pagewhich describes how the jquery.validate.unobtrusive script works.