如何使用jQuery UI日期选择器格式

How to use jQuery UI datepicker.format

本文关键字:选择器 格式 日期 UI 何使用 jQuery      更新时间:2023-09-26

以下结果在:Uncaught TypeError: Cannot read property 'formatDate' of undefined我在同一目录中有所有三个文件(jquery、jquery ui和这个html文件):

<html>
<head>
<link rel="stylesheet" href="jquery-ui.min.css">
<script src="jquery-1.11.1.min.js"</script>
<script src="jquery-ui.min.js"</script>
<script>
$(document).ready(function(){
  var $t = $.datepicker.formatDate("M dd", new Date("2014-12-01"));
  console.log($t);
});
</script>
</head>
<body>
</body>
</html>

我做错了什么?

如果这是您实际的HTML,您应该更改

<script src="jquery-1.11.1.min.js"</script>
<script src="jquery-ui.min.js"</script>

进入

<script src="jquery-1.11.1.min.js"></script>
<script src="jquery-ui.min.js"></script>

您没有正确加载jquery ui。你需要一个括号。

我使用FULL日期选择器js文件解决了同样的错误

<script src="/js/jquery.datetimepicker.full.js"></script>

可用于Git日期时间选择器/build/

HTML:

<input type="text" id="your_input" name="your_input" />

JS:

  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
  <script>
  $(function() {
    $( "#your_input" ).datepicker();
  });
  </script>

可选快速加载数据选择器:

      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
      <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
      <script>
      $(function() {
        $('body').on('focus',"#your_input", function(){
              $(this).datepicker({ dateFormat: 'dd-mm-yy' });
        });
      });
      </script>