最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use jQuery UI datepicker.format - Stack Overflow

programmeradmin1浏览0评论

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

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

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

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

Share Improve this question asked Nov 5, 2014 at 22:13 kmansoorkmansoor 4,34510 gold badges55 silver badges95 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

If this is your actual HTML, you should change

<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. You need a closing bracket.

I sloved the same error by using the FULL datepicker js file

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

available in Git Datetimepicker/build/

HTML:

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

JS:

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

Optional Fast load datapicker:

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

评论列表(0)

  1. 暂无评论