javascript - 为什么 jquery 日期选择器插件不起作用
问题描述
我正在制作待办事项网络应用程序。如果我只运行日期选择器代码,它将运行,但是当我与其他 html 代码结合使用时,它不起作用
它只显示
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<!--datepicker-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ asset("css/todolist/datepicker.css") }}">
<input type="text" class="form-control" data-toggle="datepicker">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
<script href=" {{ asset('/js/todolist/datepicker.js') }}"}}></script>
<script>
$(function() {
$('[data-toggle="datepicker"]').datepicker({
autoHide: true,
zIndex: 2048,
});
});
</script>
当我单击输入字段字段时,它应该显示日期。
解决方案
您错误地导入了datepicker.js
脚本。应该src
不是href
。您的模板语言的语法也可能有一些错误,但我不确定您使用的是什么,所以我对此不能 100% 有信心。我觉得应该是这样的
<script src="{{asset('/js/todolist/datepicker.js')}}"></script>
但绝对需要src
而不是href
。如果我复制您的代码并替换该存储库中的 Github 页面脚本,它就可以正常工作。
<script src="https://fengyuanchen.github.io/datepicker/js/datepicker.js"></script>
不过绝对不要使用 Github 页面 URL——它不应该用作 CDN。我只是用它作为一个例子来证明你的问题在于你导入该脚本的方式。
推荐阅读
- python - 通过 API 的多个 URL 从多个 JSON 中提取特定密钥
- excel - 将所有工作表中的 A 列插入新工作表的 A 列
- python - 将具有多个列表对象的字典转换为有组织的元组格式
- r - 有条件地替换data.table R中整个组的值
- javascript - 在节点组周围画一个圆圈
- vim - Verilog 模式 - 如何关闭 /* */ 评论的颜色?
- javascript - 具有多个输入的表单。是否填充显示/隐藏输入标签
- c# - C# WPF 将 DataGrid 列属性绑定到类列表
- python - 如何访问在 tf.function 中更新的张量值(例如指标)?
- javascript - 如何创建标准 ERC721 代币