Javascript(JQuery) Проблемы с datapicker.

GA
На сайте с 06.10.2010
Offline
33
611

Ребят помогите пож-та.

Вот страничка:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link type="text/css" href="./css/style.css" rel="stylesheet" > </link>
<link href="./css/smoothness/jquery-ui-1.9.1.custom.css" rel="stylesheet"></link>
<link type="text/css" href="./css/popup.css" rel="stylesheet"> </link>
<link type="text/css" href="./css/jquery.timepicker.css" rel="stylesheet"> </link>
<script src="js/addons/jquery-1.8.2.js"></script>
<script src="js/addons/jquery-ui-1.9.1.custom.js"></script>
<script src="js/addons/jquery.ui.datepicker-ru.js"></script>
<script src="js/addons/jquery.timepicker.js"></script>
<script src="js/addons/jquery.cookie.js"></script>
<script src="js/addons/jquery.json-2.4.js"></script>
<script src="js/neworder.js"></script>
</head>
<!--[if IE 7 ]> <body class="ie7"> <![endif]-->
<!--[if IE 8 ]> <body class="ie8"> <![endif]-->
<!--[if IE 9 ]> <body class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><!--<![endif]-->

<body>
<div id="ClientInfoDiv">
<div class="d-col colorblock" style="margin-left: 40px;">
<div class="f-col" style="width: 170px;">
<label> Оплатить: </label>
<input type="text" name="date_1" class="date_1" value="" id="PaymentDate"></input>
<div class="date_btn"></div>
</div>
<div class="f-col" style="width: 170px;">
<label> Выдача заказа: </label>
<input type="text" name="date_1" class="date_1" value="" id="DateEndWork"></input>
<div class="date_btn"></div>
</div>
<div class="f-col" style="width: 170px;">
<label> Время: </label>
<input type="text" name="date_1" class="date_1" value="" id="TimeEndWork"></input>
<div class="time_btn"></div>
</div>
</div>
</div>
</body>
</html>

в js/neworder.js


$(document).ready(function () {
$("#DateEndWork").datepicker();
$("#PaymentDate").datepicker();
$("#TimeEndWork").timepicker({'timeFormat': 'H:i'});
});

При таком раскладе все прекрасно отрабатывает.

Но стоит мне её грузить динамически через ajax


$.ajax({
url: 'orders/neworder.php'
, type : 'POST'
, data : PostStr
, success: function (res) {
var obj = jQuery.parseJSON(res);
$("#ClientInfoDiv").empty();
$("#ClientInfoDiv").append(obj.ClientInfo);
$("#DateEndWork").datepicker();
$("#PaymentDate").datepicker();
$("#TimeEndWork").timepicker({'timeFormat': 'H:i'});
},
error: function (res){
alert('res');
}
});

В консоль вылетает ошибка "Uncaught TypeError: undefined is not a function"

на


$("#DateEndWork").datepicker();

просто уже мозг себе сломал.. в чем не прав?

S
На сайте с 20.08.2007
Offline
140
#1

Первое, что приходит в голову - дождаться загрузки страницы, упаковав функцию в

$(document).ready(function () {

.....
});
mugukamil
На сайте с 05.11.2013
Offline
26
#2
somick:
Первое, что приходит в голову - дождаться загрузки страницы, упаковав функцию в
$(document).ready(function () {

.....
});

и еще перенести подключение скриптов в конец тега <body>

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий