我正在尝试使用时间选择器插件 ( http://trentrichardson.com/examples/timepicker/ ) 实现 jQuery UI 日期选择器。
我将 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();
有没有人遇到过这个问题。我确定我遗漏了一些简单的东西,但我一直无法找到有同样问题的人。
谢谢
最佳答案
在加载 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>
关于javascript - 用于日期选择器的 jquery 时间选择器插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15372627/