javascript - 如何在 1.12.4 版本中使用 jquery 添加日期选择器?
问题描述
我想要一个带有 jquery 1.12.4 的日期选择器。
我尝试了什么:
jQuery('input[name="dates"]').datetimepicker({
format: 'dd/mm/yyyy'
});
但我在页面中没有得到任何结果。有人知道我的代码有什么错误吗?
我在控制台中得到这个:
TypeError: jQuery(...).datetimepicker is not a function
解决方案
请注意,我在头部添加了 jquery-ui。和 style.css。我也把你写的函数改成这个:
$( "#datepicker" ).datepicker({dateFormat: "dd/mm/yy"});
现在它应该是这样的:
<!doctype html>
<html lang="en">
<head>
<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: "dd/mm/yy"});
} );
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
阅读更多:https ://api.jqueryui.com/datepicker/#option-dateFormat 代码笔:https ://codepen.io/Elnatan/pen/mdPdBEg
推荐阅读
- python - 如何在tensorflow keras中的Lambda层内获得两个张量(形状= [?,256,512])的成对欧几里得距离?
- swift - SceneKit didApplyAnimationsAtTime 计算时间
- php - 使用 volley 从 localhost mysql 通过那里的 id 获取文本或图像
- php - PHP 循环动态变量
- c - 使用 C 程序读取文本文件导致处理器以 100% 运行
- c++ - 这些指针如何不仅仅指向一个字符或一个字节?
- python - 视图 blog.views.BlogViews 没有返回 HttpResponse 对象。它返回 None 而不是
- npm - package.json 中的安装后脚本
- python - 如何从python中的父文件夹导入依赖的cython模块
- c - 如果条件在 c 中有效,为什么要在里面 printf?