3

このページでこのコードを見つけました..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css">
 <script type="text/javascript">
 $(function() {
$('.date-picker').datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    dateFormat: 'MM yy',
    onClose: function(dateText, inst) { 
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(year, month, 1));
    }
});
});
</script>
 <style>
  .ui-datepicker-calendar {
display: none;
}
</style>
</head>
<body>
    <label for="startDate">Date :</label>
    <input name="startDate" id="startDate" class="date-picker" />
</body>
</html>

同じページにカレンダーが1つしかない場合でも機能しますが、カレンダーが2つある場合、両方の日を非表示にし、それを1つのカレンダーにのみ適用したい..誰か教えてくださいどうすればいいですか?

ありがとう。

4

2 に答える 2

2

を使用$('.date-picker').datepicker({すると、すべてのカレンダーが同じ設定、特に日付形式で初期化されるため、個別に初期化する必要があります。たとえば、カレンダーに「firstCalendar」と「secondCalendar」という ID がある場合、上記のように最初のカレンダーを初期化します。

$('#firstCalendar').datepicker( {
    dateFormat: 'MM yy'
});

そして、デフォルトのdateFormatを持つ2番目のもの:

$('#secondCalendar').datepicker( {
    dateFormat: 'mm/dd/yy'
});
于 2012-11-14T17:17:37.827 に答える