Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สอบถาม datepicker เวอชั่นใหม่ครับ input ในช่องกลายเป็นปี คศ ครับ



 

สอบถาม datepicker เวอชั่นใหม่ครับ input ในช่องกลายเป็นปี คศ ครับ

 



Topic : 116433



โพสกระทู้ ( 279 )
บทความ ( 0 )



สถานะออฟไลน์




datepicker

สอบถาม datepicker แสดงผลปีเป็น พ.ศ ครับ ผมโหลดเวอชั่นล่าสุดมาใช้


ผมแก้ไขได้ตามภาพแล้ว แต่เวลากดเลือกแสดงปี พศ และเมื่อเลือก ข้อมูลในช่องมันยังแสดงปีเป็น คศ อยู่เลยครับ

ผมแก้ไขโดยดูจากตัวอยา่งนี้
https://www.thaicreate.com/community/how-to-localize-datepicker.html

แต่อันนี้เวอชั่นเก่า ของเวอชั่นใหม่มันเขียนอีกแบบนึงเลยงงครับ
ผมแก้ได้แบบในภาพ แต่พอ input ในช่องดันกลายเป็นปี คศ อยู่อีกครับ

ขอคำแนะนำหน่อยครับ



Tag : PHP, jQuery









ประวัติการแก้ไข
2015-05-12 14:58:40
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-05-12 14:58:09 By : lhumdin View : 1550 Reply : 3
 

 

No. 1



โพสกระทู้ ( 708 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ลองใช้ของผมดูครับ วางไฟล์ผมไว้ล่างสุด

<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

var dateBefore = null; 
$.datepicker.setDefaults({
	showOn: "both",
	buttonImage: "images/calendar.gif",
	buttonImageOnly: true,
	changeMonth: true,
	changeYear: true,
	dateFormat: "yy-mm-dd",
	dayNamesMin: ['อา', 'จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'],   
	monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],  
	monthNamesShort: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],  
	beforeShow:function(){  
		var altFieldId = $(this).attr("id")+"display"; 
		if(typeof $("#"+altFieldId).val() === "undefined"){
			var altField = $(this).clone();
			$(altField).attr("id", altFieldId);
			$(this).before(altField);
			$(this).hide();
			$("#"+altFieldId).on("focus", function(){
				$("#"+altFieldId.replace("display", "")).trigger("focus");
			});
		}  
		if($(this).val()!=""){ 
			var now = new Date();
			var arrayDate=$(this).val().split("-");     
			arrayDate[0]=parseInt(arrayDate[0])+543;  
			$("#"+altFieldId).val(arrayDate[2]+"/"+arrayDate[1]+"/"+arrayDate[0]);  
		}  
		setTimeout(function(){
			var textYear = parseInt($("span.ui-datepicker-year").html())+543;
			$("span.ui-datepicker-year").html(textYear);  
			$.each($(".ui-datepicker-year option"),function(j,k){  
				var textYear=parseInt($(".ui-datepicker-year option").eq(j).val())+543;  
				$(".ui-datepicker-year option").eq(j).text(textYear);  
			});               
		},50);  
	}, 
	onChangeMonthYear: function(){  
		setTimeout(function(){  
			var textYear = parseInt($("span.ui-datepicker-year").html())+543;
			$("span.ui-datepicker-year").html(textYear);
			$.each($(".ui-datepicker-year option"),function(j,k){  
				var textYear=parseInt($(".ui-datepicker-year option").eq(j).val())+543;  
				$(".ui-datepicker-year option").eq(j).text(textYear);  
			});               
		},50);        
	},  
	onClose:function(dateText, inst){
		if($(this).val()!="" && $(this).val()==inst.lastVal){           
			var altFieldId = $(this).attr("id")+"display"; 
			var arrayDate=inst.lastVal.split("-");  
			arrayDate[0]=parseInt(arrayDate[0])+543;  
			$("#"+altFieldId).val(arrayDate[2]+"/"+arrayDate[1]+"/"+arrayDate[0]);     
		}         
	},  
	onSelect: function(dateText, inst){   
		var altFieldId = $(this).attr("id")+"display"; 
		var arrayDate=dateText.split("-");  
		arrayDate[0]=parseInt(arrayDate[0])+543;  
		$("#"+altFieldId).val(arrayDate[2]+"/"+arrayDate[1]+"/"+arrayDate[0]);  
	}
});

$.fn.setDate = function(date){
	this.datepicker("setDate", date);
	var altFieldId = $(this).attr("id")+"display"; 
	var altField = $(this).clone();
	$(altField).attr("id", altFieldId);
	$(this).before(altField);
	$(this).hide();
	$("#"+altFieldId).on("focus", function(){
		$("#"+altFieldId.replace("display", "")).trigger("focus");
	});
	var arrayDate=$(this).val().split("-");     
	arrayDate[0]=parseInt(arrayDate[0])+543;  
	$("#"+altFieldId).val(arrayDate[2]+"/"+arrayDate[1]+"/"+arrayDate[0]);   	
};







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-12 17:10:06 By : kerb
 


 

No. 2



โพสกระทู้ ( 279 )
บทความ ( 0 )



สถานะออฟไลน์


ไม่ได้ครับ error อะ

นี่โค้ดผมครับ

ผมแก้ตรง <option value='"+f+"'"+(f===i?" selected='selected'":"")+">"+(f+543)+"</option>

จาก +f+ เป็น +(f+543)+ เหลือแค่ตรง input มะรู้เติมตรงไหน นั่งแกะตั้งแต่เช้าจนมืดด ใครพอมองออกบ้างช่วยหน่อยครับ
++ ผมมือใหม่ครับ

ผมเริ่มหาที่แก้ตั้งแต่ที่หาคำว่า generateMonthYearHeader ตามด้านบนเขียนไว้ครับ

Code (JavaScript)
_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?"":"&#xa0;")),!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);
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?"":"&#xa0;")+_),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
 

 

No. 3



โพสกระทู้ ( 1,095 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


http://www.ninenik.com/content.php?arti_id=309
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-12 21:55:54 By : compiak
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถาม datepicker เวอชั่นใหม่ครับ input ในช่องกลายเป็นปี คศ ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่