日期选择器的jquery时间选择器插件

时间:2013-03-12 21:35:39

标签: javascript jquery datetimepicker timepicker

我正在尝试使用Time Picker插件(http://trentrichardson.com/examples/timepicker/)实现jQuery UI Date Picker。

我将js和css分别保存在与我的脚本相同的目录中,分别为timpicker.js和picker.css。

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Select a Date Range</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<link rel="stylesheet" href="picker.css" />
<script src="timepicker.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$('#from').datetimepicker();
</script>
</head>
<body>
<label for="from">From</label>
<input type="text" id="from" name="from" />
</body>
</html>

Firebug不断给我这些错误:

ReferenceError: jQuery is not defined
[Break On This Error]   

})(jQuery);

datetimepicker.js (line 1919)

TypeError: $(...).datetimepicker is not a function
[Break On This Error]   

$('#from').datetimepicker();

有没有其他人遇到过这个问题。我确定我错过了一些简单的东西,但我一直找不到任何有同样问题的人。

谢谢

1 个答案:

答案 0 :(得分:6)

在加载jQuery之前加载timepicker.js。您的页面正在尝试运行timepicker.js,并且对jQuery一无所知。重新排列脚本,如:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script src="timepicker.js"></script>