我正在尝试使用此插件将时间选择器放入表单中:http://jonthornton.github.io/jquery-timepicker/。看起来我所要做的就是下载库并使用 jQuery 和 jQuery ui,但到目前为止我无法让它工作,即使 jQuery 的日期选择器工作得很好。
这是我的代码:
<link rel="stylesheet" href="/jquery-ui.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="js/timepicker.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script src="js/timepicker.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
$(function() {
$('#timepicker1').timepicker();
});
</script>
<form method="post" action = "makecleaningappt">
What day would you like a cleaning?
<input type="text" id="datepicker" name = "date">
What time would you like to start?<br>(example format: 3 pm)
<input type="text" id="timepicker1" name = "time" >
...
当我在 Firefox 中运行此命令时,出现以下错误:
TypeError: $(...).timepicker is not a function
我也尝试过不在 lambda 函数中嵌入对 timepicker 的 js 调用。我还尝试将 timepicker id 附加到 div 元素。这些选项都不起作用。我在其他 SO 帖子中看到,此错误通常是在存在命名冲突时出现的,但除了包含 timepicker.css 和 timepicker.js 文件之外,我的代码中没有任何名为“timepicker”的内容。
如果有任何解决此问题的建议,我将不胜感激。谢谢!
该代码适用于您拥有的 jQuery 和 jQuery ui 版本。我更新了您的代码以使用硬编码路径并且代码运行。
$(function() {
$("#datepicker").datepicker();
});
$(function() {
$('#timepicker1').timepicker();
});
<link rel="stylesheet" href="/jquery-ui.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<!-- Updated stylesheet url -->
<link rel="stylesheet" href="//jonthornton.github.io/jquery-timepicker/jquery.timepicker.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<!-- Updated JavaScript url -->
<script src="//jonthornton.github.io/jquery-timepicker/jquery.timepicker.js"></script>
<form method="post" action="makecleaningappt">
What day would you like a cleaning?
<input type="text" id="datepicker" name="date">What time would you like to start?
<br>(example format: 3 pm)
<input type="text" id="timepicker1" name="time">
</form>
这意味着 JavaScript 文件不在您要查找的位置。控制台可能有一条消息:“无法加载资源:服务器响应状态为 404(未找到)"
如果该文件存在,请检查以确保 JS 文件中确实包含内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)