当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery UI 实例讲解 - 日期选择器(Datepicker)

jQuery UI 实例讲解 - 日期选择器(Datepicker)

2017年12月12日  | 移动技术网IT编程  | 我要评论

默认功能

日期选择器(datepicker)绑定到一个标准的表单 input 字段上。把焦点移到 input 上(点击或者使用 tab 键),在一个小的覆盖层上打开一个交互日历。选择一个日期,点击页面上的任意地方(输入框即失去焦点),或者点击 esc 键来关闭。如果选择了一个日期,则反馈显示为 input 的值。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 默认功能</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker(); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"></p> 
 
 
</body> 
</html> 

  

动画

当打开或关闭 datepicker 时使用不同的动画。从下拉框中选择一个动画,然后在输入框中点击来查看它的效果。您可以使用三个标准动画中任意一个,或者使用 ui 特效中的任意一个。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 动画</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
  $( "#datepicker" ).datepicker(); 
  $( "#anim" ).change(function() { 
   $( "#datepicker" ).datepicker( "option", "showanim", $( this ).val() ); 
  }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker" size="30"></p> 
 
<p>动画:<br> 
 <select id="anim"> 
  <option value="show">show (默认)</option> 
  <option value="slidedown">滑下</option> 
  <option value="fadein">淡入</option> 
  <option value="blind">blind (ui 百叶窗特效)</option> 
  <option value="bounce">bounce (ui 反弹特效)</option> 
  <option value="clip">clip (ui 剪辑特效)</option> 
  <option value="drop">drop (ui 降落特效)</option> 
  <option value="fold">fold (ui 折叠特效)</option> 
  <option value="slide">slide (ui 滑动特效)</option> 
  <option value="">无</option> 
 </select> 
</p> 
 
 
</body> 
</html>

其他月份的日期

datepicker 可以显示其他月份的日期,这些日期也可以设置成可选择的。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 其他月份的日期</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker({ 
  showothermonths: true, 
  selectothermonths: true
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"></p> 
 
 
</body> 
</html> 

显示按钮栏

通过布尔值的 showbuttonpanel 选项为选择当天日期显示一个"today"按钮,为关闭日历显示一个"done"按钮。默认情况下,当按钮栏显示时会启用每个按钮,但是按钮可通过其他的选项进行关闭。按钮文本可自定义。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 显示按钮栏</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker({ 
  showbuttonpanel: true
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"></p> 
 
 
</body> 
</html>

内联显示

datepicker 是嵌套在页面中显示,而不是显示在一个覆盖层中。只需要简单地在 div 上调用 .datepicker() 即可,而不是在 input 上调用。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 内联显示</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker(); 
 }); 
 </script> 
</head> 
<body> 
 
日期:<div id="datepicker"></div> 
 
 
</body> 
</html> 

显示月份 & 年份菜单

显示月份和年份的下拉框,而不是显示静态的月份/年份标题,这样便于在大范围的时间跨度上导航。添加布尔值 changemonth和 changeyear 选项即可。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 显示月份 & 年份菜单</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker({ 
  changemonth: true, 
  changeyear: true
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"></p> 
 
 
</body> 
</html> 

显示多个月份

设置 numberofmonths 选项为一个整数 2,或者大于 2 的整数,来在一个 datepicker 中显示多个月份。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 显示多个月份</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker({ 
  numberofmonths: 3, 
  showbuttonpanel: true
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"></p> 
 
 
</body> 
</html> 

格式化日期

以各种方式显示日期反馈。从下拉框中选择一种日期格式,然后在输入框中点击并选择一个日期,查看所选格式的日期显示。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 格式化日期</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker(); 
 $( "#format" ).change(function() { 
  $( "#datepicker" ).datepicker( "option", "dateformat", $( this ).val() ); 
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker" size="30"></p> 
 
<p>格式选项:<br> 
 <select id="format"> 
 <option value="mm/dd/yy">default - mm/dd/yy</option> 
 <option value="yy-mm-dd">iso 8601 - yy-mm-dd</option> 
 <option value="d m, y">short - d m, y</option> 
 <option value="d mm, y">medium - d mm, y</option> 
 <option value="dd, d mm, yy">full - dd, d mm, yy</option> 
 <option value="'day' d 'of' mm 'in the year' yy">with text - 'day' d 'of' mm 'in the year' yy</option> 
 </select> 
</p> 
 
 
</body> 
</html>

图标触发器

点击输入框旁边的图标来显示 datepicker。设置 datepicker 在获得焦点时打开(默认行为),或者在点击图标时打开,或者在获得焦点/点击图标时打开。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 图标触发器</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker({ 
  showon: "button", 
  buttonimage: "images/calendar.gif", 
  buttonimageonly: true
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"></p> 
 
 
</body> 
</html>

本地化日历

本地化 datepicker 日历语言和格式(默认为 english / western 格式)。datepicker 包含对从右到左读取的语言的内建支持,比如 arabic 和 hebrew。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 本地化日历</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <script src="http://jqueryui.com/resources/demos/datepicker/jquery.ui.datepicker-ar.js"></script> 
 <script src="http://jqueryui.com/resources/demos/datepicker/jquery.ui.datepicker-fr.js"></script> 
 <script src="http://jqueryui.com/resources/demos/datepicker/jquery.ui.datepicker-he.js"></script> 
 <script src="http://jqueryui.com/resources/demos/datepicker/jquery.ui.datepicker-zh-tw.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker( $.datepicker.regional[ "fr" ] ); 
 $( "#locale" ).change(function() { 
  $( "#datepicker" ).datepicker( "option", 
  $.datepicker.regional[ $( this ).val() ] ); 
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"> 
 <select id="locale"> 
 <option value="ar">arabic (?(???????</option> 
 <option value="zh-tw">chinese traditional (繁體中文)</option> 
 <option value="">english</option> 
 <option value="fr" selected="selected">french (fran?ais)</option> 
 <option value="he">hebrew (?(?????</option> 
 </select></p> 
 
 
</body> 
</html>

填充另一个输入框

使用 altfield 和 altformat 选项,无论何时选择日期,会在另一个输入框中填充带有一定格式的日期。这个功能通过对电脑友好性的日期进一步加工后,向用户呈现一个用户友好性的日期。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 填充另一个输入框</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker({ 
  altfield: "#alternate", 
  altformat: "dd, d mm, yy"
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"> <input type="text" id="alternate" size="30"></p> 
 
 
</body> 
</html>

限制日期范围

通过 mindate 和 maxdate 选项限制可选择的日期范围。设置起止日期为实际的日期(new date(2009, 1 - 1, 26)),或者为与今天的一个数值偏移(-20),或者为一个周期和单位的字符串('+1m +10d')。如果设置为字符串,使用 'd' 表示天,使用 'w' 表示周,使用 'm' 表示月,使用 'y' 表示年。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 限制日期范围</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker({ mindate: -20, maxdate: "+1m +10d" }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"></p> 
 
 
</body> 
</html> 

选择一个日期范围

选择要搜索的日期范围。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 选择一个日期范围</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#from" ).datepicker({ 
  defaultdate: "+1w", 
  changemonth: true, 
  numberofmonths: 3, 
  onclose: function( selecteddate ) { 
  $( "#to" ).datepicker( "option", "mindate", selecteddate ); 
  } 
 }); 
 $( "#to" ).datepicker({ 
  defaultdate: "+1w", 
  changemonth: true, 
  numberofmonths: 3, 
  onclose: function( selecteddate ) { 
  $( "#from" ).datepicker( "option", "maxdate", selecteddate ); 
  } 
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<label for="from">从</label> 
<input type="text" id="from" name="from"> 
<label for="to">到</label> 
<input type="text" id="to" name="to"> 
 
 
</body> 
</html>

显示一年中的第几周

datepicker 可以显示一年中的第几周。默认的计算是按照 iso 8601 定义:每周从星期一开始,每年的第一周包含该年的第一个星期四。这就意味着一年中的一些天可能是属于另一年中的周。

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="utf-8"> 
 <title>jquery ui 日期选择器(datepicker) - 显示一年中的第几周</title> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> 
 <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > 
 <script> 
 $(function() { 
 $( "#datepicker" ).datepicker({ 
  showweek: true, 
  firstday: 1 
 }); 
 }); 
 </script> 
</head> 
<body> 
 
<p>日期:<input type="text" id="datepicker"></p> 
 
 
</body> 
</html> 

jquery的datepicker变成中文:jquery.ui.datepicker-zh-cn.js一般会找这个js,我把这个js的代码拿出来,以后就不需要再在网上找啦:

jquery(function($){ 
 $.datepicker.regional['zh-cn'] = { 
  closetext: '关闭', 
  prevtext: '<上月', 
  nexttext: '下月>', 
  currenttext: '今天', 
  monthnames: ['一月','二月','三月','四月','五月','六月', 
  '七月','八月','九月','十月','十一月','十二月'], 
  monthnamesshort: ['一','二','三','四','五','六', 
  '七','八','九','十','十一','十二'], 
  daynames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'], 
  daynamesshort: ['周日','周一','周二','周三','周四','周五','周六'], 
  daynamesmin: ['日','一','二','三','四','五','六'], 
  weekheader: '周', 
  dateformat: 'yy-mm-dd', 
  firstday: 1, 
  isrtl: false, 
  showmonthafteryear: true, 
  yearsuffix: '年'}; 
 $.datepicker.setdefaults($.datepicker.regional['zh-cn']); 
}); 

以上这篇jquery ui 实例讲解 - 日期选择器(datepicker)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网