2015-02-23 103 views
0

我在下面的鏈接下面用datepicker製作了'月份日曆'。 當我點擊按鈕,日曆出來,並顯示。這是我的問題。任何人都知道如何改變這個命令在jQuery日期選擇器中改變月份和年份之間的位置

1.month 2.year1.year 2.month

http://develop-for-fun.blogspot.kr/2013/08/jquery-ui-datepicker-month-and-year.html

 $(function() { 
      $('#MainContent_txtMonth').datepicker({ 
       changeYear: true, 
       changeMonth: true, 
       showButtonPanel: true, 
       dateFormat: 'yy-mm', 
       monthNamesShort: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'], 
       showOn: "button", 
       buttonImage: "img/button_calendar.jpg", 
       buttonImageOnly: true 
       }).focus(function() { 
       var thisCalendar = $(this); 
       $('.ui-datepicker-calendar').detach(); 
       $('.ui-datepicker-close').click(function() { 
       var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
       var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
       thisCalendar.datepicker('setDate', new Date(year, month, 1)); 
       }); 
      }); 
     }); 
+0

你爲什麼不改變生成的HTML? – Kosmog 2015-02-23 08:00:01

+0

@Kosmo生成的HTML有** 2個選擇標記**並且具有**'onchange'event **。我不知道如何更改生成的標籤。 – naanace 2015-02-23 08:14:22

+0

我已經發布了一個答案 – Kosmog 2015-02-23 08:23:13

回答

2

您不必修改jquery ui源代碼。我剛剛找到了一個你想要的選項。用法

showMonthAfterYear:true, 

例子:

$("#datepicker").datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     showButtonPanel: true, 
     showMonthAfterYear:true, 
     dateFormat: 'MM yy', 
     }); 
+0

哦,它的工作原理!謝謝@Kosmo!你節省了我的時間 – naanace 2015-02-23 08:31:38

+0

很高興它的作品。祝你今天愉快 ! – Kosmog 2015-02-23 08:35:21

相關問題