简体   繁体   English

如何使用 jQuery UI datepicker.format

[英]How to use jQuery UI datepicker.format

The following results in: Uncaught TypeError: Cannot read property 'formatDate' of undefined I have all three files in the same directory (jquery, jquery-ui and this html file):结果如下: 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>

What am I doing wrong?我究竟做错了什么?

If this is your actual HTML, you should change如果这是您的实际 HTML,您应该更改

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

into进入

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

You aren't loading the jquery-ui properly.您没有正确加载 jquery-ui。 You need a closing bracket.你需要一个右括号。

HTML: HTML:

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

JS: 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>

Optional Fast load datapicker:可选的快速加载数据选择器:

      <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>

I sloved the same error by using the FULL datepicker js file我使用完整的 datepicker js 文件解决了同样的错误

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

available in Git Datetimepicker/build/Git Datetimepicker/build/ 中可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM