object doesn't support property or method datepicker

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

I am trying to put a datepicker in my page and getting this error. I already searched and looked for other answers to this error, but couldn't find any.

Without the FOR BOOTSTRAP part, it works; but with it, I am getting this error. What is the reason behind this and how can I fix this?

Here is my index.cshtml:

@{     Layout = null; }  <!DOCTYPE html>  <html lang="en"> <head>      @Scripts.Render("~/bundles/jquery")     @Scripts.Render("~/bundles/jqueryui")     @Styles.Render("~/Content/css")     @Scripts.Render("~/bundles/modernizr")     @Scripts.Render("~/bundles/Chart")     @Scripts.Render("~/bundles/moment")     <meta charset="utf-8" />     <title>ENOCTA DASHBOARD</title>      <!-- FOR DATEPICKER -->     <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">     <script src="//code.jquery.com/jquery-1.10.2.js"></script>     <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>     <link rel="stylesheet" href="/resources/demos/style.css">     <script>         $(function () {             $("#datepicker").datepicker();         });     </script>      <!-- FOR BOOTSTRAP -->     <meta name="viewport" content="width=device-width, initial-scale=1">     <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>     <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>  </head>  <body>     <p>Date: <input type="text" id="datepicker"></p> </body>  </html> 

回答1:

You have 2 versions of jQuery on the page, the jQuery UI datepicker hangs itself into the first version, then the second one overwrites the first one and thus the datepicker is not available when the DOMContentReady event is fired. The solution is to move the second jquery include up and remove the first one:

<!-- FOR DATEPICKER --> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"> <script>     $(function () {         $("#datepicker").datepicker();     }); </script>  <!-- FOR BOOTSTRAP --> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!