月と年を受け入れる日付フィールドがあります。ただし、ユーザーがフィールドを選択するたびに、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>
編集:少し明確にするために、次のケースで日付ピッカーの日付を比較します。ここでは、入力の値に日を指定し、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>