2016-12-07 53 views
1

我想在同一頁面上有兩個不同的primeface日曆。p:僅限月和年的日曆

一個帶日期和時間的日曆,只有月和年。

我已經使用下面的JavaScript和css的日曆只有月和年。 它工作正常,但其他日曆也受到影響,並且由於以下CSS樣式而不顯示日期。 有什麼辦法可以爲特定日曆應用樣式而不是所有?

的JavaScript: -

$(".monthPicker").datepicker({  
     dateFormat: 'M yy', 
     changeMonth: true, 
     changeYear: true, 
     showButtonPanel: true, 
     maxDate: $.now() , 

     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).val($.datepicker.formatDate('M yy', new Date(year,month, 1))); 
     } 
    }); 
    $(".monthPicker").datepicker("option", "maxDate", new Date()); 
    $(".monthPicker").focus(function() { 
     $(".ui-datepicker-calendar").hide(); 
     $("#ui-datepicker-div").position({ 
      my: "center top", 
      at: "center bottom", 
      of: $(this) 
     }); 
    }); 

CSS: -

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

我沒有看到任何PrimeFaces在這個問題... – Kukeltje

+0

號碼:日曆是primefaces歷... @Kukeltje – Harshal

+1

但沒有號碼:日曆你的代碼在上面。可能你只是使用簡單的jquet日曆(因爲這是你使用'$(「。monthPicker」)所做的事情)。datepicker(...) – Kukeltje

回答

0

您只需將另一個標記類這種datepickers的,就像這樣:

$(".monthPicker").datepicker({ 
 
     beforeShow : function(input, instance){ 
 
      instance.dpDiv.addClass("month-picker") 
 
     } 
 
});
.month-picker 
 
{ 
 
    border: 2px solid pink 
 
}
<script 
 
    src="https://code.jquery.com/jquery-2.2.4.min.js" 
 
    integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" 
 
    crossorigin="anonymous"></script> 
 
<script 
 
    src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" 
 
    integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" 
 
    crossorigin="anonymous"></script> 
 

 
<input type="text" class="monthPicker" />

現在您可以選擇:

.ui-datepicker.month-picker