|
 |
|
เรื่อง datepicker ครับ มันไม่เป็นภาษาไทยถ้าใส่ฟังชั่นบางตัวเข้าไป |
|
 |
|
|
 |
 |
|
อันนี้โค้ดครับ
Code (PHP)
<script type="text/javascript">
$(function () {
var d = new Date();
var toDay = d.getDate() + '/' + (d.getMonth() + 1) + '/' + (d.getFullYear() + 543);
var datepicked = function() {
var from = $('#datepickerthai_in');
var to = $('#datepickerthai_out');
var fromDate = from.datepicker('getDate');
var toDate = to.datepicker('getDate');
if(toDate && fromDate){
if (toDate.getTime() < fromDate.getTime()){
alert('วันที่สิ้นสุดน้อยกว่าวันที่เริ่ม');
$('#datepickerthai_out').val('');
}
}
}
function noWeekends(date) {
var d = date.getDay();
return [d !== 0 && d !== 6, "", ""];
}
$("#datepickerthai_in , #datepickerthai_out").datepicker({
onSelect: datepicked,
dateFormat: 'yy-mm-dd',
minDate: 0,
maxDate: "",
beforeShowDay: noWeekends });
$( "#datepickerthai_in" ).datepicker({dateFormat: 'dd/mm/yy', isBuddhist: true, defaultDate: toDay, dayNames: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'],
dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'],
monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']});
$( "#datepickerthai_out" ).datepicker({dateFormat: 'dd/mm/yy', isBuddhist: true, defaultDate: toDay, dayNames: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'],
dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'],
monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']});
$("#datepickerthai_in").datepicker({ dateFormat: 'yy-mm-dd'});
$("#datepickerthai_out").datepicker({ dateFormat: 'yy-mm-dd'});
$("#inline").datepicker({ dateFormat: 'yy-mm-dd', inline: true });
});
</script>
แต่พอเอา function ข้างบนออกมันเป็นภาษาไทยปกติ
Code (PHP)
<script type="text/javascript">
$(function () {
var d = new Date();
var toDay = d.getDate() + '/' + (d.getMonth() + 1) + '/' + (d.getFullYear() + 543);
$( "#datepickerthai_in" ).datepicker({dateFormat: 'dd/mm/yy', isBuddhist: true, defaultDate: toDay, dayNames: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'],
dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'],
monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']});
$( "#datepickerthai_out" ).datepicker({dateFormat: 'dd/mm/yy', isBuddhist: true, defaultDate: toDay, dayNames: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'],
dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'],
monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']});
$("#datepickerthai_in").datepicker({ dateFormat: 'yy-mm-dd'});
$("#datepickerthai_out").datepicker({ dateFormat: 'yy-mm-dd'});
$("#inline").datepicker({ dateFormat: 'yy-mm-dd', inline: true });
});
</script>
อยากได้โค้ดบนแต่ให้เป็นภาษาไทย อะครับช่วยหน่อยนะ 
Tag : PHP, JavaScript, jQuery

|
|
 |
 |
 |
 |
Date :
2013-04-24 11:24:28 |
By :
white31969 |
View :
1588 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันเกี่ยวกันตรงไหนครับ ? 
|
 |
 |
 |
 |
Date :
2013-04-24 17:14:35 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดซ้ำซ้อนมากๆ ครับ
<script type="text/javascript">
$(function () {
var d = new Date();
var toDay = d.getDate() + '/' + (d.getMonth() + 1) + '/' + (d.getFullYear() + 543);
var datepicked = function() {
var from = $('#datepickerthai_in');
var to = $('#datepickerthai_out');
var fromDate = from.datepicker('getDate');
var toDate = to.datepicker('getDate');
if(toDate && fromDate){
if (toDate.getTime() < fromDate.getTime()){
alert('วันที่สิ้นสุดน้อยกว่าวันที่เริ่ม');
$('#datepickerthai_out').val('');
}
}
}
function noWeekends(date) {
var d = date.getDay();
return [d !== 0 && d !== 6, "", ""];
}
$("#datepickerthai_in , #datepickerthai_out").datepicker({
onSelect: datepicked,
dateFormat: 'yy-mm-dd',
minDate: 0,
maxDate: "",
beforeShowDay: noWeekends
});
$( "#datepickerthai_in" ).datepicker({dateFormat: 'dd/mm/yy', isBuddhist: true, defaultDate: toDay, dayNames: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'],
dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'],
monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']
});
$( "#datepickerthai_out" ).datepicker({dateFormat: 'dd/mm/yy', isBuddhist: true, defaultDate: toDay, dayNames: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'],
dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'],
monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']
});
$("#datepickerthai_in").datepicker({ dateFormat: 'yy-mm-dd'});
$("#datepickerthai_out").datepicker({ dateFormat: 'yy-mm-dd'});
$("#inline").datepicker({ dateFormat: 'yy-mm-dd', inline: true });
});
</script>
ที่ทำแยกสีไว้ หมายถึงการสร้าง datepicker 1 ครั้ง
ซึ่งในโปรกรมนี้มี datepicker แค่ 3 ตัวคือ
#datepickerthai_in
#datepickerthai_out
และ
#inline
แต่คุณเรียก datepicker() ไปกี่ครั้งครับ
และที่ว่าถ้าตัดสีแดงออกแล้วจะเป็นภาษาไทยเหมือนเดิม มันก็ถูกต้องแล้วครับ
เพราะพอคุณสร้าง #datepickerthai_in และ #datepickerthai_out (สีแดง) ไปแล้ว
คุณมาสร้างซ้ำ (สีเขียวและสีน้ำเงิน) มันก็ไม่มีผลแล้วครับ เพราะมันเป็น datepicker (ที่ไม่ได้กำหนดภาษา) ไปแล้ว
ดังนั้นคิดใหม่ทำใหม่ครับ รวมโค้ดเข้าด้วยกัน
Code (JavaScript)
<script type="text/javascript">
$(function () {
var d = new Date();
var toDay = d.getDate() + '/' + (d.getMonth() + 1) + '/' + (d.getFullYear() + 543);
var datepicked = function() {
var from = $('#datepickerthai_in');
var to = $('#datepickerthai_out');
var fromDate = from.datepicker('getDate');
var toDate = to.datepicker('getDate');
if(toDate && fromDate){
if (toDate.getTime() < fromDate.getTime()){
alert('วันที่สิ้นสุดน้อยกว่าวันที่เริ่ม');
$('#datepickerthai_out').val('');
}
}
}
function noWeekends(date) {
var d = date.getDay();
return [d !== 0 && d !== 6, "", ""];
}
$("#datepickerthai_in , #datepickerthai_out").datepicker({
isBuddhist: true,
defaultDate: toDay,
dayNames: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'],
dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'],
monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.'],
onSelect: datepicked,
dateFormat: 'yy-mm-dd',
minDate: 0,
maxDate: "",
beforeShowDay: noWeekends
});
$("#inline").datepicker({ dateFormat: 'yy-mm-dd', inline: true });
});
</script>
|
 |
 |
 |
 |
Date :
2013-04-25 00:49:34 |
By :
cookiephp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จัดไปครับ
|
 |
 |
 |
 |
Date :
2013-04-25 06:23:25 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ๋อ มิน่าล่ะ เห็นในตัวอย่างคนอื่นเขาเอามารวมกัน แต่ผมไม่เข้าใจและทำไม่เป็น Y_Y
ขอบคุณมากเลยครับ จาลองหัดเขียนเองมั่ง 
|
 |
 |
 |
 |
Date :
2013-04-25 08:37:50 |
By :
white31969 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|