我想在联系表单上包含一个jquery datepicker。
不幸的是,它不是因为一个未知的原因而工作(它在同一网站上以其他形式工作)
有人可以帮助澄清为什么它不起作用?它只是在没有任何弹出窗口的情况下充当文本框:
请注意:表格存放在一张卡片中,不确定这是否会影响它,但我听说过表格和卡片混合不好
脚本:
<link rel="stylesheet"
href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js">
</script>
<script>
$( function() {
$( "#datepicker" ).datepicker({
dateFormat: "yy-mm-dd"
});
} );
</script>
<div class="form-group">
<label for="datepicker">Pick a date</label>
<input type="text" date-date-format="yy-mm-dd" name="datepicker"
id="datepicker" class="form-control">
</div>
控制台返回:
未捕获的TypeError:$(...)。datepicker不是HTMLDocument的函数。 (index.php:20)at(jquery-1.12.4.js:3232)at Function.readyWith [as resolveWith](jquery-1.12.4.js:3362)at Function.ready(jquery-1.12.4。 js:3582)在HTMLDocument.completed(jquery-1.12.4.js:3617)
发现了这个问题。看来我在页面底部有我认为不相关的脚本,两者发生冲突并导致错误
我建议使用谷歌CDN,而不是jQuery的服务器。由于您使用的是php,因此您可能需要在脚本标记中添加type =“text / javascript”,以查看是否会产生影响。
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>