Код работает в песочнице, но не работает при импорте в файлы, что делать? - jQuery
Код работает в песочнице, но не работает при импорте в файлы. Вроде библиотеки подключил, скрипт обернул. Не понимаю, код в песочнице работает, а импортированных файлах нет. Прошу у вас помощи! Заранее спасибо
Ссылка на код в песочнице https://jsfiddle.net/z6toko4y/ Вот что пишет консоль: Failed to load resource: net::ERR_FILE_NOT_FOUND jquery-ui.js Failed to load resource: net::ERR_FILE_NOT_FOUND jquery.min.js:2 jQuery.Deferred exception: $(...).datepicker is not a function TypeError: $(...).datepicker is not a function at HTMLDocument.<anonymous> (file:///C:/Users/%D0%9F%D0%9A/Desktop/123/script.js:2:31) at j (https://ajax.googleapis.com/ajax/lib...min.js:2:29948) at k (https://ajax.googleapis.com/ajax/lib...min.js:2:30262) undefined r.Deferred.exceptionHook @ jquery.min.js:2 jquery.min.js:2 jQuery.Deferred exception: $(...).datepicker is not a function TypeError: $(...).datepicker is not a function at HTMLDocument.<anonymous> (file:///C:/Users/%D0%9F%D0%9A/Desktop/123/index.html:17:31) at j (https://ajax.googleapis.com/ajax/lib...min.js:2:29948) at k (https://ajax.googleapis.com/ajax/lib...min.js:2:30262) undefined r.Deferred.exceptionHook @ jquery.min.js:2 jquery.min.js:2 Uncaught TypeError: $(...).datepicker is not a function at HTMLDocument.<anonymous> (script.js:2) at j (jquery.min.js:2) at k (jquery.min.js:2) jquery.min.js:2 Uncaught TypeError: $(...).datepicker is not a function at HTMLDocument.<anonymous> (index.html:17) at j (jquery.min.js:2) at k (jquery.min.js:2) Сам код: HTLM <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title><!-- Title here --></title> <link data-require="jqueryui" data-semver="1.10.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.0/css/smoothness/jquery-ui-1.10.0.custom.min.css" /> <link rel="stylesheet" href="style.css" /> <script data-require="jquery" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script data-require="jqueryui" data-semver="1.10.0" src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.0/jquery-ui.js"></script> <script src="script.js"></script> </head> <body> <script> $(document).ready(function() { var dates = $( "#from, #to" ).datepicker({ dateFormat: "dd-mm-yy", onSelect: function( selectedDate ) { var option = this.id == "from" ? "minDate" : "maxDate", instance = $( this ).data( "datepicker" ), date = $.datepicker.parseDate( instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); } }); }; </script> <p> <label for="from">с:</label> <input type="text" id="from" name="from"/> <label for="to">до:</label> <input type="text" id="to" name="to"/> </p> <!-- Put your html here! --> </body> </html> CSS body { font: 12px Arial, sans-serif; } JS $(document).ready(function() { var dates = $( "#from, #to" ).datepicker({ dateFormat: "dd-mm-yy", onSelect: function( selectedDate ) { var option = this.id == "from" ? "minDate" : "maxDate", instance = $( this ).data( "datepicker" ), date = $.datepicker.parseDate( instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); } }); }); |
Nere,
попробуйте добавить https: там где нет. и [js] ... ваш код... [/js] О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting. |
Мне кажется дело в версии библиотеки
Вот что пишет консоль: Failed to load resource: net::ERR_FILE_NOT_FOUND jquery-ui.js Failed to load resource: net::ERR_FILE_NOT_FOUND jquery.min.js:2 jQuery.Deferred exception: $(...).datepicker is not a function TypeError: $(...).datepicker is not a function at HTMLDocument.<anonymous> (file:///C:/Users/%D0%9F%D0%9A/Desktop/123/script.js:2:31) at j (https://ajax.googleapis.com/ajax/lib...min.js:2:29948) at k (https://ajax.googleapis.com/ajax/lib...min.js:2:30262) undefined r.Deferred.exceptionHook @ jquery.min.js:2 jquery.min.js:2 jQuery.Deferred exception: $(...).datepicker is not a function TypeError: $(...).datepicker is not a function at HTMLDocument.<anonymous> (file:///C:/Users/%D0%9F%D0%9A/Desktop/123/index.html:17:31) at j (https://ajax.googleapis.com/ajax/lib...min.js:2:29948) at k (https://ajax.googleapis.com/ajax/lib...min.js:2:30262) undefined r.Deferred.exceptionHook @ jquery.min.js:2 jquery.min.js:2 Uncaught TypeError: $(...).datepicker is not a function at HTMLDocument.<anonymous> (script.js:2) at j (jquery.min.js:2) at k (jquery.min.js:2) jquery.min.js:2 Uncaught TypeError: $(...).datepicker is not a function at HTMLDocument.<anonymous> (index.html:17) at j (jquery.min.js:2) at k (jquery.min.js:2) |
Nere,
незагружено у вас всё что не имеет https: src="https: //cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.0/jquery-ui.js" добавить красное везде где нет!!! |
посмотрел какие ошибки пишет консоль, добавил к ссылкам https, изменил версии библиотек на нужные. Все работает) Спасибо за ответы)
|
Часовой пояс GMT +3, время: 03:39. |