内容简介:翻译自:https://stackoverflow.com/questions/27211228/uncaught-typeerror-cannot-read-property-addmethod-of-undefined
jQuery(document).ready(function () { //alert("HIQ"); $('.mySelectCalendar').datepicker({ firstDay: 1, dateFormat: "dd.mm.yy" }); $.validator.addMethod( 'date', function (value, element, params) { if (this.optional(element)) { return true; }; var result = false; try { $.datepicker.parseDate('dd.mm.yy', value); result = true; } catch (err) { result = false; } return result; }, '' ); });
我得到错误“未捕获的TypeError:无法读取未定义的属性’addMethod’”
_layout就是这样
@ ViewBag.Title
<!-- jQuery --> <script src="~/App_Themes/ThemeBlue/assets/js/jquery203.js"></script> <script src="~/App_Themes/ThemeBlue/assets/js/jquery.min.js"></script> <script type="text/javascript"> var jQuery_2_0_3 = $.noConflict(true); </script> <!-- Picker UI--> <script src="~/App_Themes/ThemeBlue/assets/js/jquery-ui.js"></script> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script> <!--Validation --> <script src="~/Scripts/jquery-1.7.1.min.js"></script> <script src="~/Scripts/jquery.validate.js"></script> <script src="~/Scripts/jquery.validate.unobtrusive.js"></script> <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script> <link href="~/App_Themes/ThemeBlue/css/validation.css" rel="stylesheet" /> <script type="text/javascript"> var jQuery_1_7_0 = $.noConflict(true); </script> <!-- Bootstrap --> <link href="~/App_Themes/ThemeBlue/dist/css/bootstrap.css" rel="stylesheet" media="screen" /> <link href="~/App_Themes/ThemeBlue/assets/css/custom.css" rel="stylesheet" media="screen" /> <!-- bin/jquery.slider.min.js --> <script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/jshashtable-2.1_src.js"></script> <script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/jquery.numberformatter-1.2.3.js"></script> <script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/tmpl.js"></script> <script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/jquery.dependClass-0.1.js"></script> <script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/draggable-0.1.js"></script> <script type="text/javascript" src="~/App_Themes/ThemeBlue/plugins/jslider/js/jquery.slider.js"></script> <!-- Javascript --> <script src="~/App_Themes/ThemeBlue/assets/js/initialize-loginpage.js"></script> <script src="~/App_Themes/ThemeBlue/assets/js/jquery.easing.js"></script> <script src="~/App_Themes/ThemeBlue/assets/js/customTravel.js"></script> <!-- Load Animo --> <script src="~/App_Themes/ThemeBlue/plugins/animo/animo.js"></script> <script src="~/App_Themes/ThemeBlue/dist/js/bootstrap.min.js"></script> <!-- Carousel --> <link href="~/App_Themes/ThemeBlue/examples/carousel/carousel.css" rel="stylesheet" /> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="assets/js/html5shiv.js"></script> <script src="assets/js/respond.min.js"></script> <![endif]--> <!-- Fonts --> <link href='http://fonts.googleapis.com/css?family=Lato:400,100,100italic,300,300italic,400italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Open+Sans:700,400,300,300italic' rel='stylesheet' type='text/css'> <!-- Font-Awesome --> <link rel="stylesheet" type="text/css" href="~/App_Themes/ThemeBlue/assets/css/font-awesome.css" media="screen" /> <!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="~/App_Themes/ThemeBlue/assets/css/font-awesome-ie7.css" media="screen" /><![endif]--> <!-- REVOLUTION BANNER CSS SETTINGS --> <link rel="stylesheet" type="text/css" href="~/App_Themes/ThemeBlue/css/fullwidth.css" media="screen" /> <link rel="stylesheet" type="text/css" href="~/App_Themes/ThemeBlue/rs-plugin/css/settings2.css" media="screen" /> <!-- Picker UI--> <link rel="stylesheet" href="~/App_Themes/ThemeBlue/assets/css/jquery-ui.css" /> <!-- bin/jquery.slider.min.css --> <link rel="stylesheet" href="~/App_Themes/ThemeBlue/plugins/jslider/css/jslider.css" type="text/css"> <link rel="stylesheet" href="~/App_Themes/ThemeBlue/plugins/jslider/css/jslider.round.css" type="text/css"> <!-- Animo css--> <link href="~/App_Themes/ThemeBlue/plugins/animo/animate_animo.css" rel="stylesheet" media="screen"> <!-- end -->
我在MVC中编写Web应用程序并无法解决此问题.
你可以帮帮我吗?
你的错误:
Uncaught TypeError: Cannot read property ‘addMethod’ of undefined
它只是意味着JavaScript无法找到addMethod方法,该方法内置于jQuery Validate插件中.没有正确包含jQuery或jQuery Validate …无法找到文件或者jQuery被破坏了…
你的头部是乱七八糟的jQuery和.noConflict()应用不一致.
注意如何在包含这个特定版本的jQuery之后定义.noConflict()?
<!--Validation --> <script src="~/Scripts/jquery-1.7.1.min.js"></script> <script src="~/Scripts/jquery.validate.js"></script> .... <script type="text/javascript"> var jQuery_1_7_0 = $.noConflict(true); // <- this </script>
因此,对于验证部分,名称jQuery_1_7_0必须在验证代码中替换每个实例$.
jQuery_1_7_0(document).ready(function () { jQuery_1_7_0.validator.addMethod( ....
我只指出了一个例子.您还在验证部分上方添加了一个没有.noConflict()的jQuery版本.
需要解析这些多个版本的jQuery,方法是删除重复项并保留一个版本,或者在包含每个版本后正确使用.noConflict().
IMO,最好只使用一个版本的jQuery.
翻译自:https://stackoverflow.com/questions/27211228/uncaught-typeerror-cannot-read-property-addmethod-of-undefined
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- JqueryUI自动完成错误:未捕获TypeError:对象#的属性“结果”不是函数
- js捕获错误信息
- Python捕获所有异常
- Android NativeCrash 捕获与解析
- Wireshark如何捕获USB流量
- 在 Docker 容器中捕获信号
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。