【发布时间】:2012-07-31 18:57:42
【问题描述】:
我们有一个接受月份和年份的日期字段。但是,每当用户选择该字段时,jQuery UI Datepicker 默认为当前月份和年份,并清除他们输入的任何内容。
我已将测试用例中的格式切换为 mm/dd/yy,并且 Datepicker 的行为正确,因此我相当确信基本代码是正确的。
关于如何解决此问题的任何建议?
示例代码如下:
<html>
<head></head>
<body>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.min.js"></script>
<input type="text" id="asdf" value="07/2006" />
<script type="text/javascript">
$('#asdf').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'mm/yy',
showButtonPanel: true
});
</script>
</body>
</html>
编辑:为了更清楚一点,在以下情况下比较 Datepicker 的日期,我们在输入值中提供一天,并更改 dateFormat 选项:
<html>
<head></head>
<body>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.min.js"></script>
<input type="text" id="asdf" value="07/01/2006" />
<script type="text/javascript">
$('#asdf').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'mm/dd/yy',
showButtonPanel: true
});
</script>
</body>
</html>
【问题讨论】:
标签: jquery-ui datepicker