简体   繁体   中英

JQuery - datepicker doesn't appear

I am new in JQuery and I need to use datepicker to get date in form. I am using this code:

HTML

<html>
 <head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <script>
   $(function() {
     $( "#date" ).focus().datepicker({ dateFormat: 'dd-mm-yy' });
   });
  </script>
 </head>
 <body>
  <p>Date: <input type="text" id="date"></p>
 </body>
</html>

But when I click on field, nothing happen. When I tried to use this:

<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>

<div id="datepicker"></div>

<script>
$( "#datepicker" ).datepicker();
</script>

</body>
</html>

It is working... Thanks for tips.

Additionally: I am using Nette framework, where I can inherit templates... Could this be the problem?

Just focus it after you've initialized the datepicker, otherwise the input is focused before there is a datepicker attached.

$( "#date" ).datepicker({ dateFormat: 'dd-mm-yy' }).focus();

FIDDLE

尝试使用如下选项进行初始化:

$('#date').datepicker( "option", "dateFormat", 'dd-mm-yy' ).datepicker();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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