 |
|
|
 |
 |
|
ลองใช้ของผมดูครับ วางไฟล์ผมไว้ล่างสุด
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/jquery-ui.min.js'></script>
<script type='text/javascript' src='js/jquery-thaidatepicker.js'></script>
jquery-thaidatepicker.js
01. var dateBefore = null ;
02. $.datepicker.setDefaults({
03. showOn: "both" ,
04. buttonImage: "images/calendar.gif" ,
05. buttonImageOnly: true ,
06. changeMonth: true ,
07. changeYear: true ,
08. dateFormat: "yy-mm-dd" ,
09. dayNamesMin: [ 'อา' , 'จ' , 'อ' , 'พ' , 'พฤ' , 'ศ' , 'ส' ],
10. monthNames: [ 'มกราคม' , 'กุมภาพันธ์' , 'มีนาคม' , 'เมษายน' , 'พฤษภาคม' , 'มิถุนายน' , 'กรกฎาคม' , 'สิงหาคม' , 'กันยายน' , 'ตุลาคม' , 'พฤศจิกายน' , 'ธันวาคม' ],
11. monthNamesShort: [ 'มกราคม' , 'กุมภาพันธ์' , 'มีนาคม' , 'เมษายน' , 'พฤษภาคม' , 'มิถุนายน' , 'กรกฎาคม' , 'สิงหาคม' , 'กันยายน' , 'ตุลาคม' , 'พฤศจิกายน' , 'ธันวาคม' ],
12. beforeShow: function (){
13. var altFieldId = $( this ).attr( "id" )+ "display" ;
14. if ( typeof $( "#" +altFieldId).val() === "undefined" ){
15. var altField = $( this ).clone();
16. $(altField).attr( "id" , altFieldId);
17. $( this ).before(altField);
18. $( this ).hide();
19. $( "#" +altFieldId).on( "focus" , function (){
20. $( "#" +altFieldId.replace( "display" , "" )).trigger( "focus" );
21. });
22. }
23. if ($( this ).val()!= "" ){
24. var now = new Date();
25. var arrayDate=$( this ).val().split( "-" );
26. arrayDate[0]=parseInt(arrayDate[0])+543;
27. $( "#" +altFieldId).val(arrayDate[2]+ "/" +arrayDate[1]+ "/" +arrayDate[0]);
28. }
29. setTimeout( function (){
30. var textYear = parseInt($( "span.ui-datepicker-year" ).html())+543;
31. $( "span.ui-datepicker-year" ).html(textYear);
32. $.each($( ".ui-datepicker-year option" ), function (j,k){
33. var textYear=parseInt($( ".ui-datepicker-year option" ).eq(j).val())+543;
34. $( ".ui-datepicker-year option" ).eq(j).text(textYear);
35. });
36. },50);
37. },
38. onChangeMonthYear: function (){
39. setTimeout( function (){
40. var textYear = parseInt($( "span.ui-datepicker-year" ).html())+543;
41. $( "span.ui-datepicker-year" ).html(textYear);
42. $.each($( ".ui-datepicker-year option" ), function (j,k){
43. var textYear=parseInt($( ".ui-datepicker-year option" ).eq(j).val())+543;
44. $( ".ui-datepicker-year option" ).eq(j).text(textYear);
45. });
46. },50);
47. },
48. onClose: function (dateText, inst){
49. if ($( this ).val()!= "" && $( this ).val()==inst.lastVal){
50. var altFieldId = $( this ).attr( "id" )+ "display" ;
51. var arrayDate=inst.lastVal.split( "-" );
52. arrayDate[0]=parseInt(arrayDate[0])+543;
53. $( "#" +altFieldId).val(arrayDate[2]+ "/" +arrayDate[1]+ "/" +arrayDate[0]);
54. }
55. },
56. onSelect: function (dateText, inst){
57. var altFieldId = $( this ).attr( "id" )+ "display" ;
58. var arrayDate=dateText.split( "-" );
59. arrayDate[0]=parseInt(arrayDate[0])+543;
60. $( "#" +altFieldId).val(arrayDate[2]+ "/" +arrayDate[1]+ "/" +arrayDate[0]);
61. }
62. });
63.
64. $.fn.setDate = function (date){
65. this .datepicker( "setDate" , date);
66. var altFieldId = $( this ).attr( "id" )+ "display" ;
67. var altField = $( this ).clone();
68. $(altField).attr( "id" , altFieldId);
69. $( this ).before(altField);
70. $( this ).hide();
71. $( "#" +altFieldId).on( "focus" , function (){
72. $( "#" +altFieldId.replace( "display" , "" )).trigger( "focus" );
73. });
74. var arrayDate=$( this ).val().split( "-" );
75. arrayDate[0]=parseInt(arrayDate[0])+543;
76. $( "#" +altFieldId).val(arrayDate[2]+ "/" +arrayDate[1]+ "/" +arrayDate[0]);
77. };
|
 |
 |
 |
 |
Date :
2015-05-12 17:10:06 |
By :
kerb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้ครับ error อะ
นี่โค้ดผมครับ
ผมแก้ตรง <option value='"+f+"'"+(f===i?" selected='selected'":"")+">"+(f+543)+"</option>
จาก +f+ เป็น +(f+543)+ เหลือแค่ตรง input มะรู้เติมตรงไหน นั่งแกะตั้งแต่เช้าจนมืดด ใครพอมองออกบ้างช่วยหน่อยครับ
++ ผมมือใหม่ครับ
ผมเริ่มหาที่แก้ตั้งแต่ที่หาคำว่า generateMonthYearHeader ตามด้านบนเขียนไว้ครับ
Code (JavaScript)
1. _generateMonthYearHeader: function (e,t,i,s,a,n,o,r){ var h,l,u,d,c,p,f,m,g= this ._get(e, "changeMonth" ),v= this ._get(e, "changeYear" ),y= this ._get(e, "showMonthAfterYear" ),b= "<div class='ui-datepicker-title'>" ,_= "" ; if (n||!g)_+= "<span class='ui-datepicker-month'>" +o[t]+ "</span>" ; else { for (h=s&&s.getFullYear()===i,l=a&&a.getFullYear()===i,_+= "<select class='ui-datepicker-month' data-handler='selectMonth' data-event='change'>" ,u=0;12>u;u++)(!h||u>=s.getMonth())&&(!l||a.getMonth()>=u)&&(_+= "<option value='" +u+ "'" +(u===t? " selected='selected'" : "" )+ ">" +r[u]+ "</option>" );_+= "</select>" } if (y||(b+=_+(!n&&g&&v? "" : " " )),!e.yearshtml) if (e.yearshtml= "" ,n||!v)b+= "<span class='ui-datepicker-year'>" +(i)+ "</span>" ; else { for (d= this ._get(e, "yearRange" ).split( ":" ),c=( new Date).getFullYear(),p= function (e){ var t=e.match(/c[+\-].*/)?i+parseInt(e.substring(1),10):e.match(/[+\-].*/)?c+parseInt(e,10):parseInt(e,10);
2. return isNaN(t)?c:t},f=p(d[0]),m=Math.max(f,p(d[1]|| "" )),f=s?Math.max(f,s.getFullYear()):f,m=a?Math.min(m,a.getFullYear()):m,e.yearshtml+= "<select class='ui-datepicker-year' data-handler='selectYear' data-event='change'>" ;m>=f;f++)e.yearshtml+= "<option value='" +f+ "'" +(f===i? " selected='selected'" : "" )+ ">" +(f+543)+ "</option>" ;e.yearshtml+= "</select>" ,b+=e.yearshtml,e.yearshtml= null } return b+= this ._get(e, "yearSuffix" ),y&&(b+=(!n&&g&&v? "" : " " )+_),b+= "</div>" },_adjustInstDate: function (e,t,i){ var s=e.drawYear+( "Y" ===i?t:0),a=e.drawMonth+( "M" ===i?t:0),n=Math.min(e.selectedDay, this ._getDaysInMonth(s,a))+( "D" ===i?t:0),o= this ._restrictMinMax(e, this ._daylightSavingAdjust( new Date(s,a,n)));e.selectedDay=o.getDate(),e.drawMonth=e.selectedMonth=o.getMonth(),e.drawYear=e.selectedYear=o.getFullYear(),( "M" ===i|| "Y" ===i)&& this ._notifyChange(e)},_restrictMinMax: function (e,t){ var i= this ._getMinMaxDate(e, "min" ),s= this ._getMinMaxDate(e, "max" ),a=i&&i>t?i:t; return s&&a>s?s:a},_notifyChange: function (e){ var t= this ._get(e, "onChangeMonthYear" );t&&t.apply(e.input?e.input[0]: null ,[e.selectedYear,e.selectedMonth+1,e])},_getNumberOfMonths: function (e){ var t= this ._get(e, "numberOfMonths" ); return null ==t?[1,1]: "number" == typeof t?[1,t]:t},_getMinMaxDate: function (e,t){ return this ._determineDate(e, this ._get(e,t+ "Date" ), null )},_getDaysInMonth: function (e,t){ return 32- this ._daylightSavingAdjust( new Date(e,t,32)).getDate()},_getFirstDayOfMonth: function (e,t){ return new Date(e,t,1).getDay()},_canAdjustMonth: function (e,t,i,s){ var a= this ._getNumberOfMonths(e),n= this ._daylightSavingAdjust( new Date(i,s+(0>t?t:a[0]*a[1]),1)); return 0>t&&n.setDate( this ._getDaysInMonth(n.getFullYear(),n.getMonth())), this ._isInRange(e,n)},_isInRange: function (e,t){ var i,s,a= this ._getMinMaxDate(e, "min" ),n= this ._getMinMaxDate(e, "max" ),o= null ,r= null ,h= this ._get(e, "yearRange" ); return h&&(i=h.split( ":" ),s=( new Date).getFullYear(),o=parseInt(i[0],10),r=parseInt(i[1],10),i[0].match(/[+\-].*/)&&(o+=s),i[1].match(/[+\-].*/)&&(r+=s)),(!a||t.getTime()>=a.getTime())&&(!n||t.getTime()<=n.getTime())&&(!o||t.getFullYear()>=o)&&(!r||r>=t.getFullYear())},_getFormatConfig: function (e){ var t= this ._get(e, "shortYearCutoff" ); return t= "string" != typeof t?t:( new Date).getFullYear()%100+parseInt(t,10),{shortYearCutoff:t,dayNamesShort: this ._get(e, "dayNamesShort" ),dayNames: this ._get(e, "dayNames" ),monthNamesShort: this ._get(e, "monthNamesShort" ),monthNames: this ._get(e, "monthNames" )}},_formatDate: function (e,t,i,s){t||(e.currentDay=e.selectedDay,e.currentMonth=e.selectedMonth,e.currentYear=e.selectedYear); var a=t? "object" == typeof t?t: this ._daylightSavingAdjust( new Date(s,i,t)): this ._daylightSavingAdjust( new Date(e.currentYear,e.currentMonth,e.currentDay)); return this .formatDate( this ._get(e, "dateFormat" ),a, this ._getFormatConfig(e))}}),e.fn.datepicker= function (t){ if (! this .length) return this ;e.datepicker.initialized||(e(document).mousedown(e.datepicker._checkExternalClick),e.datepicker.initialized=!0),0===e( "#" +e.datepicker._mainDivId).length&&e( "body" ).append(e.datepicker.dpDiv); var i=Array.prototype.slice.call(arguments,1); return "string" != typeof t|| "isDisabled" !==t&& "getDate" !==t&& "widget" !==t? "option" ===t&&2===arguments.length&& "string" == typeof arguments[1]?e.datepicker[ "_" +t+ "Datepicker" ].apply(e.datepicker,[ this [0]].concat(i)): this .each( function (){ "string" == typeof t?e.datepicker[ "_" +t+ "Datepicker" ].apply(e.datepicker,[ this ].concat(i)):e.datepicker._attachDatepicker( this ,t)}):e.datepicker[ "_" +t+ "Datepicker" ].apply(e.datepicker,[ this [0]].concat(i))},e.datepicker= new i,e.datepicker.initialized=!1,e.datepicker.uuid=( new Date).getTime(),e.datepicker.version= "1.10.4" })(jQuery);
|
ประวัติการแก้ไข 2015-05-12 21:38:24 2015-05-12 21:40:38 2015-05-12 21:42:48
 |
 |
 |
 |
Date :
2015-05-12 21:37:08 |
By :
lhumdin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|