簡體   English   中英

jQuery UI DatePicker僅在一個日歷中顯示月份

[英]jQuery UI DatePicker to show month year only in one calendar

我在這個頁面找到了這個代碼..

<!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>

並且如果你在同一頁面只有一個日歷,但是如果我有兩個日歷,則隱藏兩者中的日期,並且我希望僅在一個日歷中應用這些日歷。有人可以告訴我我該怎么做?

謝謝。

通過使用$('.date-picker').datepicker({你使用相同的設置初始化所有日歷,特別是日期格式,所以你需要單獨初始化它們。例如,如果你的日歷有id“firstCalendar”和“secondCalendar” ,首先如上所示:

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

第二個是默認的dateFormat:

$('#secondCalendar').datepicker( {
    dateFormat: 'mm/dd/yy'
});

你需要刪除

.ui-datepicker-calendar {
   display: none;
}

試試這個jsfiddle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM