【发布时间】:2014-04-14 07:19:18
【问题描述】:
有没有办法在一个下拉菜单中组合月份和年份下拉元素。 新的下拉列表应包含“04/2014”、“05/2014”等元素,直至最大日期。
【问题讨论】:
-
这是一个“不工作”的演示:jsfiddle.net/afLjk/71
标签: jquery datepicker customization
有没有办法在一个下拉菜单中组合月份和年份下拉元素。 新的下拉列表应包含“04/2014”、“05/2014”等元素,直至最大日期。
【问题讨论】:
标签: jquery datepicker customization
这是一种 hacky 方法,但您可以这样做:
将 changeYear 和 changeMonth 设置为 false。向正文添加委托的单击侦听器。
$('body').on('click', '#ui-datepicker-title', function() { ... });
在函数主体获取当前年/月的地方,使用所需的值填充自定义 div 并将 div 放置在日期选择器的标题上。
【讨论】:
试试这个
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<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>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
【讨论】: