首页 > 解决方案 > 如何在 1.12.4 版本中使用 jquery 添加日期选择器?

问题描述

我想要一个带有 jquery 1.12.4 的日期选择器。

我尝试了什么:

jQuery('input[name="dates"]').datetimepicker({
        format: 'dd/mm/yyyy'
    });

但我在页面中没有得到任何结果。有人知道我的代码有什么错误吗?

我在控制台中得到这个:

TypeError: jQuery(...).datetimepicker is not a function 

标签: javascriptjquery

解决方案


请注意,我在头部添加了 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


推荐阅读