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,038

HOME > Client Script Forum > รับค่าจากปฏิทินลง textbox แต่อยากแก้จากปี คศ เป็นปี พศ อ่ะครับ


[PHP] รับค่าจากปฏิทินลง textbox แต่อยากแก้จากปี คศ เป็นปี พศ อ่ะครับ

 
Topic : 078660



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



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



iiijlhjlhk

อยากให้เป็นปี พ ศ ครับ ผมลองแก้หาดูแล้วแต่ก็ไม่ได้ซะที ผู้ที่มีความรู้ทางด้าน JS รบกวนช่วยดูให้ด้วยนะครับ ขอบคุณครับ

Code (JavaScript)
001./*****************************************************************************
002.Copyright (C) 2006  Nick Baicoianu
003. 
004.This program is free software; you can redistribute it and/or
005.modify it under the terms of the GNU General Public License
006.as published by the Free Software Foundation; either version 2
007.of the License, or (at your option) any later version.
008. 
009.This program is distributed in the hope that it will be useful,
010.but WITHOUT ANY WARRANTY; without even the implied warranty of
011.MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012.GNU General Public License for more details.
013. 
014.You should have received a copy of the GNU General Public License
015.along with this program; if not, write to the Free Software
016.Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
017.*****************************************************************************/
018.//constructor for the main Epoch class (ENGLISH VERSION)
019.function Epoch(name,mode,targetelement,multiselect)
020.{
021.    this.state = 0;
022.    this.name = name;
023.    this.curDate = new Date();
024.    this.mode = mode;
025.    this.selectMultiple = (multiselect == true); //'false' is not true or not set at all
026.     
027.    //the various calendar variables
028.    //this.selectedDate = this.curDate;
029.    this.selectedDates = new Array();
030.    this.calendar;
031.    this.calHeading;
032.    this.calCells;
033.    this.rows;
034.    this.cols;
035.    this.cells = new Array();
036.     
037.    //The controls
038.    this.monthSelect;
039.    this.yearSelect;
040.     
041.    //standard initializations
042.    this.mousein = false;
043.    this.calConfig();
044.    this.setDays();
045.    this.displayYear = this.displayYearInitial;
046.    this.displayMonth = this.displayMonthInitial;
047.     
048.    this.createCalendar(); //create the calendar DOM element and its children, and their related objects
049.     
050.    if(this.mode == 'popup' && targetelement && targetelement.type == 'text') //if the target element has been set to be an input text box
051.    {
052.        this.tgt = targetelement;
053.        this.calendar.style.position = 'absolute';
054.        this.topOffset = this.tgt.offsetHeight; // the vertical distance (in pixels) to display the calendar from the Top of its input element
055.        this.leftOffset = 0;                    // the horizontal distance (in pixels) to display the calendar from the Left of its input element
056.        this.calendar.style.top = this.getTop(targetelement) + this.topOffset + 'px';
057.        this.calendar.style.left = this.getLeft(targetelement) + this.leftOffset + 'px';
058.        document.body.appendChild(this.calendar);
059.        this.tgt.calendar = this;
060.        this.tgt.onfocus = function () {this.calendar.show();}; //the calendar will popup when the input element is focused
061.        this.tgt.onblur = function () {if(!this.calendar.mousein){this.calendar.hide();}}; //the calendar will popup when the input element is focused
062.    }
063.    else
064.    {
065.        this.container = targetelement;
066.        this.container.appendChild(this.calendar);
067.    }
068.     
069.    this.state = 2; //0: initializing, 1: redrawing, 2: finished!
070.    this.visible ? this.show() : this.hide();
071.}
072.//-----------------------------------------------------------------------------
073.Epoch.prototype.calConfig = function () //PRIVATE: initialize calendar variables
074.{
075.    //this.mode = 'flat'; //can be 'flat' or 'popup'
076.    this.displayYearInitial = this.curDate.getFullYear(); //the initial year to display on load
077.    this.displayMonthInitial = this.curDate.getMonth(); //the initial month to display on load (0-11)
078.    this.rangeYearLower = 2012;
079.    this.rangeYearUpper = 2112;
080.    this.minDate = new Date(2012,0,1);
081.    this.maxDate = new Date(2112,0,1);
082.    this.startDay = 0; // the day the week will 'start' on: 0(Sun) to 6(Sat)
083.    this.showWeeks = true; //whether the week numbers will be shown
084.    this.selCurMonthOnly = false; //allow user to only select dates in the currently displayed month
085.    this.clearSelectedOnChange = true; //whether to clear all selected dates when changing months
086.     
087.    //flat mode-only settings:
088.    //this.selectMultiple = true; //whether the user can select multiple dates (flat mode only)
089. 
090.    switch(this.mode) //set the variables based on the calendar mode
091.    {
092.        case 'popup': //popup options
093.            this.visible = false;
094.            break;
095.        case 'flat':
096.            this.visible = true;
097.             
098.            break;
099.    }
100.    this.setLang();
101.};
102.//-----------------------------------------------------------------------------
103.Epoch.prototype.setLang = function()  //all language settings for Epoch are made here.  Check Date.dateFormat() for the Date object's language settings
104.{
105.    this.daylist = new Array('Su','Mo','Tu','We','Th','Fr','Sa','Su','Mo','Tu','We','Th','Fr','Sa'); /*<lang:en>*/
106.    this.months_sh = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
107.    this.monthup_title = 'Go to the next month';
108.    this.monthdn_title = 'Go to the previous month';
109.    this.clearbtn_caption = 'Clear';
110.    this.clearbtn_title = 'Clears any dates selected on the calendar';
111.    this.maxrange_caption = 'This is the maximum range';
112.};
113.//-----------------------------------------------------------------------------
114.Epoch.prototype.getTop = function (element) //PRIVATE: returns the absolute Top value of element, in pixels
115.{
116.    var oNode = element;
117.    var iTop = 0;
118.     
119.    while(oNode.tagName != 'BODY') {
120.        iTop += oNode.offsetTop;
121.        oNode = oNode.offsetParent;
122.    }
123.     
124.    return iTop;
125.};
126.//-----------------------------------------------------------------------------
127.Epoch.prototype.getLeft = function (element) //PRIVATE: returns the absolute Left value of element, in pixels
128.{
129.    var oNode = element;
130.    var iLeft = 0;
131.     
132.    while(oNode.tagName != 'BODY') {
133.        iLeft += oNode.offsetLeft;
134.        oNode = oNode.offsetParent;       
135.    }
136.     
137.    return iLeft;
138.};
139.//-----------------------------------------------------------------------------
140.Epoch.prototype.show = function () //PUBLIC: displays the calendar
141.{
142.    this.calendar.style.display = 'block';
143.    this.visible = true;
144.};
145.//-----------------------------------------------------------------------------
146.Epoch.prototype.hide = function () //PUBLIC: Hides the calendar
147.{
148.    this.calendar.style.display = 'none';
149.    this.visible = false;
150.};
151.//-----------------------------------------------------------------------------
152.Epoch.prototype.toggle = function () //PUBLIC: Toggles (shows/hides) the calendar depending on its current state
153.{
154.    if(this.visible) {
155.        this.hide();
156.    }
157.    else {
158.        this.show();
159.    }
160.};
161.//-----------------------------------------------------------------------------
162.Epoch.prototype.setDays = function ()  //PRIVATE: initializes the standard Gregorian Calendar parameters
163.{
164.    this.daynames = new Array();
165.    var j=0;
166.    for(var i=this.startDay; i< this.startDay + 7;i++) {
167.        this.daynames[j++] = this.daylist[i];
168.    }
169.         
170.    this.monthDayCount = new Array(31,((this.curDate.getFullYear() - 2000) % 4 ? 28 : 29),31,30,31,30,31,31,30,31,30,31);
171.};
172.//-----------------------------------------------------------------------------
173.Epoch.prototype.setClass = function (element,className) //PRIVATE: sets the CSS class of the element, W3C & IE
174.{
175.    element.setAttribute('class',className);
176.    element.setAttribute('className',className); //<iehack>
177.};
178.//-----------------------------------------------------------------------------
179.Epoch.prototype.createCalendar = function ()  //PRIVATE: creates the full DOM implementation of the calendar
180.{
181.    var tbody, tr, td;
182.    this.calendar = document.createElement('table');
183.    this.calendar.setAttribute('id',this.name+'_calendar');
184.    this.setClass(this.calendar,'calendar');
185.    //to prevent IE from selecting text when clicking on the calendar
186.    this.calendar.onselectstart = function() {return false;};
187.    this.calendar.ondrag = function() {return false;};
188.    tbody = document.createElement('tbody');
189.     
190.    //create the Main Calendar Heading
191.    tr = document.createElement('tr');
192.    td = document.createElement('td');
193.    td.appendChild(this.createMainHeading());
194.    tr.appendChild(td);
195.    tbody.appendChild(tr);
196.     
197.    //create the calendar Day Heading
198.    tr = document.createElement('tr');
199.    td = document.createElement('td');
200.    td.appendChild(this.createDayHeading());
201.    tr.appendChild(td);
202.    tbody.appendChild(tr);
203. 
204.    //create the calendar Day Cells
205.    tr = document.createElement('tr');
206.    td = document.createElement('td');
207.    td.setAttribute('id',this.name+'_cell_td');
208.    this.calCellContainer = td; //used as a handle for manipulating the calendar cells as a whole
209.    td.appendChild(this.createCalCells());
210.    tr.appendChild(td);
211.    tbody.appendChild(tr);
212.     
213.    //create the calendar footer
214.    tr = document.createElement('tr');
215.    td = document.createElement('td');
216.    td.appendChild(this.createFooter());
217.    tr.appendChild(td);
218.    tbody.appendChild(tr);
219.     
220.    //add the tbody element to the main calendar table
221.    this.calendar.appendChild(tbody);
222. 
223.    //and add the onmouseover events to the calendar table
224.    this.calendar.owner = this;
225.    this.calendar.onmouseover = function() {this.owner.mousein = true;};
226.    this.calendar.onmouseout = function() {this.owner.mousein = false;};
227.};
228.//-----------------------------------------------------------------------------
229.Epoch.prototype.createMainHeading = function () //PRIVATE: Creates the primary calendar heading, with months & years
230.{
231.    //create the containing <div> element
232.    var container = document.createElement('div');
233.    container.setAttribute('id',this.name+'_mainheading');
234.    this.setClass(container,'mainheading');
235.    //create the child elements and other variables
236.    this.monthSelect = document.createElement('select');
237.    this.yearSelect = document.createElement('select');
238.    var monthDn = document.createElement('input'), monthUp = document.createElement('input');
239.    var opt, i;
240.    //fill the month select box
241.    for(i=0;i<12;i++)
242.    {
243.        opt = document.createElement('option');
244.        opt.setAttribute('value',i);
245.        if(this.state == 0 && this.displayMonth == i) {
246.            opt.setAttribute('selected','selected');
247.        }
248.        opt.appendChild(document.createTextNode(this.months_sh[i]));
249.        this.monthSelect.appendChild(opt);
250.    }
251.    //and fill the year select box
252.    for(i=this.rangeYearLower;i<=this.rangeYearUpper;i++)
253.    {
254.        opt = document.createElement('option');
255.        opt.setAttribute('value',i);
256.        if(this.state == 0 && this.displayYear == i) {
257.            opt.setAttribute('selected','selected');
258.        }
259.        opt.appendChild(document.createTextNode(i));
260.        this.yearSelect.appendChild(opt);      
261.    }
262.    //add the appropriate children for the month buttons
263.    monthUp.setAttribute('type','button');
264.    monthUp.setAttribute('value','>');
265.    monthUp.setAttribute('title',this.monthup_title);
266.    monthDn.setAttribute('type','button');
267.    monthDn.setAttribute('value','<');
268.    monthDn.setAttribute('title',this.monthdn_title);
269.    this.monthSelect.owner = this.yearSelect.owner = monthUp.owner = monthDn.owner = this//hack to allow us to access this calendar in the events (<fix>??)
270.     
271.    //assign the event handlers for the controls
272.    monthUp.onmouseup = function () {this.owner.nextMonth();};
273.    monthDn.onmouseup = function () {this.owner.prevMonth();};
274.    this.monthSelect.onchange = function() {
275.        this.owner.displayMonth = this.value;
276.        this.owner.displayYear = this.owner.yearSelect.value;
277.        this.owner.goToMonth(this.owner.displayYear,this.owner.displayMonth);
278.    };
279.    this.yearSelect.onchange = function() {
280.        this.owner.displayMonth = this.owner.monthSelect.value;
281.        this.owner.displayYear = this.value;
282.        this.owner.goToMonth(this.owner.displayYear,this.owner.displayMonth);
283.    };
284.     
285.    //and finally add the elements to the containing div
286.    container.appendChild(monthDn);
287.    container.appendChild(this.monthSelect);
288.    container.appendChild(this.yearSelect);
289.    container.appendChild(monthUp);
290.    return container;
291.};
292.//-----------------------------------------------------------------------------
293.Epoch.prototype.createFooter = function () //PRIVATE: creates the footer of the calendar - goes under the calendar cells
294.{
295.    var container = document.createElement('div');
296.    var clearSelected = document.createElement('input');
297.    clearSelected.setAttribute('type','button');
298.    clearSelected.setAttribute('value',this.clearbtn_caption);
299.    clearSelected.setAttribute('title',this.clearbtn_title);
300.    clearSelected.owner = this;
301.    clearSelected.onclick = function() { this.owner.resetSelections(false);};
302.    container.appendChild(clearSelected);
303.    return container;
304.};
305.//-----------------------------------------------------------------------------
306.Epoch.prototype.resetSelections = function (returnToDefaultMonth)  //PRIVATE: reset the calendar's selection variables to defaults
307.{
308.    this.selectedDates = new Array();
309.    this.rows = new Array(false,false,false,false,false,false,false);
310.    this.cols = new Array(false,false,false,false,false,false,false);
311.    if(this.tgt)  //if there is a target element, clear it too
312.    {
313.        this.tgt.value = '';
314.        if(this.mode == 'popup') {//hide the calendar if in popup mode
315.            this.hide();
316.        }
317.    }
318.         
319.    if(returnToDefaultMonth == true) {
320.        this.goToMonth(this.displayYearInitial,this.displayMonthInitial);
321.    }
322.    else {
323.        this.reDraw();
324.    }
325.};
326.//-----------------------------------------------------------------------------
327.Epoch.prototype.createDayHeading = function ()  //PRIVATE: creates the heading containing the day names
328.{
329.    //create the table element
330.    this.calHeading = document.createElement('table');
331.    this.calHeading.setAttribute('id',this.name+'_caldayheading');
332.    this.setClass(this.calHeading,'caldayheading');
333.    var tbody,tr,td;
334.    tbody = document.createElement('tbody');
335.    tr = document.createElement('tr');
336.    this.cols = new Array(false,false,false,false,false,false,false);
337.     
338.    //if we're showing the week headings, create an empty <td> for filler
339.    if(this.showWeeks)
340.    {
341.        td = document.createElement('td');
342.        td.setAttribute('class','wkhead');
343.        td.setAttribute('className','wkhead'); //<iehack>
344.        tr.appendChild(td);
345.    }
346.    //populate the day titles
347.    for(var dow=0;dow<7;dow++)
348.    {
349.        td = document.createElement('td');
350.        td.appendChild(document.createTextNode(this.daynames[dow]));
351.        if(this.selectMultiple) { //if selectMultiple is true, assign the cell a CalHeading Object to handle all events
352.            td.headObj = new CalHeading(this,td,(dow + this.startDay < 7 ? dow + this.startDay : dow + this.startDay - 7));
353.        }
354.        tr.appendChild(td);
355.    }
356.    tbody.appendChild(tr);
357.    this.calHeading.appendChild(tbody);
358.    return this.calHeading;
359.};
360.//-----------------------------------------------------------------------------
361.Epoch.prototype.createCalCells = function ()  //PRIVATE: creates the table containing the calendar day cells
362.{
363.    this.rows = new Array(false,false,false,false,false,false);
364.    this.cells = new Array();
365.    var row = -1, totalCells = (this.showWeeks ? 48 : 42);
366.    var beginDate = new Date(this.displayYear,this.displayMonth,1);
367.    var endDate = new Date(this.displayYear,this.displayMonth,this.monthDayCount[this.displayMonth]);
368.    var sdt = new Date(beginDate);
369.    sdt.setDate(sdt.getDate() + (this.startDay - beginDate.getDay()) - (this.startDay - beginDate.getDay() > 0 ? 7 : 0) );
370.    //create the table element
371.    this.calCells = document.createElement('table');
372.    this.calCells.setAttribute('id',this.name+'_calcells');
373.    this.setClass(this.calCells,'calcells');
374.    var tbody,tr,td;
375.    tbody = document.createElement('tbody');
376.    for(var i=0;i<totalCells;i++)
377.    {
378.        if(this.showWeeks) //if we are showing the week headings
379.        {
380.            if(i % 8 == 0)
381.            {
382.                row++;
383.                tr = document.createElement('tr');
384.                td = document.createElement('td');
385.                if(this.selectMultiple) { //if selectMultiple is enabled, create the associated weekObj objects
386.                    td.weekObj = new WeekHeading(this,td,sdt.getWeek(),row)
387.                }
388.                else //otherwise just set the class of the td for consistent look
389.                {
390.                    td.setAttribute('class','wkhead');
391.                    td.setAttribute('className','wkhead'); //<iehack>
392.                }
393.                td.appendChild(document.createTextNode(sdt.getWeek()));        
394.                tr.appendChild(td);
395.                i++;
396.            }
397.        }
398.        else if(i % 7 == 0) //otherwise, new row every 7 cells
399.        {
400.            row++;
401.            tr = document.createElement('tr');
402.        }
403.        //create the day cells
404.        td = document.createElement('td');
405.        td.appendChild(document.createTextNode(sdt.getDate()));// +' ' +sdt.getUeDay()));
406.        var cell = new CalCell(this,td,sdt,row);
407.        this.cells.push(cell);
408.        td.cellObj = cell;
409.        sdt.setDate(sdt.getDate() + 1); //increment the date
410.        tr.appendChild(td);
411.        tbody.appendChild(tr);
412.    }
413.    this.calCells.appendChild(tbody);
414.    this.reDraw();
415.    return this.calCells;
416.};
417.//-----------------------------------------------------------------------------
418.Epoch.prototype.reDraw = function () //PRIVATE: reapplies all the CSS classes for the calendar cells, usually called after chaning their state
419.{
420.    this.state = 1;
421.    var i,j;
422.    for(i=0;i<this.cells.length;i++) {
423.        this.cells[i].selected = false;
424.    }
425.    for(i=0;i<this.cells.length;i++)
426.    {
427.        for(j=0;j<this.selectedDates.length;j++) { //if the cell's date is in the selectedDates array, set its selected property to true
428.            if(this.cells[i].date.getUeDay() == this.selectedDates[j].getUeDay() ) {
429.                this.cells[i].selected = true;
430.            }
431.        }
432. 
433.        this.cells[i].setClass();
434.    }
435.    //alert(this.selectedDates);
436.    this.state = 2;
437.};
438.//-----------------------------------------------------------------------------
439.Epoch.prototype.deleteCells = function () //PRIVATE: removes the calendar cells from the DOM (does not delete the cell objects associated with them
440.{
441.    this.calCellContainer.removeChild(this.calCellContainer.firstChild); //get a handle on the cell table (optional - for less indirection)
442.    this.cells = new Array(); //reset the cells array
443.};
444.//-----------------------------------------------------------------------------
445.Epoch.prototype.goToMonth = function (year,month) //PUBLIC: sets the calendar to display the requested month/year
446.{
447.    this.monthSelect.value = this.displayMonth = month;
448.    this.yearSelect.value = this.displayYear = year;
449.    this.deleteCells();
450.    this.calCellContainer.appendChild(this.createCalCells());
451.};
452.//-----------------------------------------------------------------------------
453.Epoch.prototype.nextMonth = function () //PUBLIC: go to the next month.  if the month is december, go to january of the next year
454.{
455.     
456.    //increment the month/year values, provided they're within the min/max ranges
457.    if(this.monthSelect.value < 11) {
458.        this.monthSelect.value++;
459.    }
460.    else
461.    {
462.        if(this.yearSelect.value < this.rangeYearUpper)
463.        {
464.            this.monthSelect.value = 0;
465.            this.yearSelect.value++;
466.        }
467.        else {
468.            alert(this.maxrange_caption);
469.        }
470.    }
471.    //assign the currently displaying month/year values
472.    this.displayMonth = this.monthSelect.value;
473.    this.displayYear = this.yearSelect.value;
474.     
475.    //and refresh the calendar for the new month/year
476.    this.deleteCells();
477.    this.calCellContainer.appendChild(this.createCalCells());
478.};
479.//-----------------------------------------------------------------------------
480.Epoch.prototype.prevMonth = function () //PUBLIC: go to the previous month.  if the month is january, go to december of the previous year
481.{
482.    //increment the month/year values, provided they're within the min/max ranges
483.    if(this.monthSelect.value > 0)
484.        this.monthSelect.value--;
485.    else
486.    {
487.        if(this.yearSelect.value > this.rangeYearLower)
488.        {
489.            this.monthSelect.value = 11;
490.            this.yearSelect.value--;
491.        }
492.        else {
493.            alert(this.maxrange_caption);
494.        }
495.    }
496.     
497.    //assign the currently displaying month/year values
498.    this.displayMonth = this.monthSelect.value;
499.    this.displayYear = this.yearSelect.value;
500.     
501.    //and refresh the calendar for the new month/year
502.    this.deleteCells();
503.    this.calCellContainer.appendChild(this.createCalCells());
504.};
505.//-----------------------------------------------------------------------------
506.Epoch.prototype.addZero = function (vNumber) //PRIVATE: pads a 2 digit number with a leading zero
507.{
508.    return ((vNumber < 10) ? '0' : '') + vNumber;
509.};
510.//-----------------------------------------------------------------------------
511.Epoch.prototype.addDates = function (dates,redraw)  //PUBLIC: adds the array "dates" to the calendars selectedDates array (no duplicate dates) and redraws the calendar
512.{
513.    var j,in_sd;
514.    for(var i=0;i<dates.length;i++)
515.    {  
516.        in_sd = false;
517.        for(j=0;j<this.selectedDates.length;j++)
518.        {
519.            if(dates[i].getUeDay() == this.selectedDates[j].getUeDay())
520.            {
521.                in_sd = true;
522.                break;
523.            }
524.        }
525.        if(!in_sd) { //if the date isn't already in the array, add it!
526.            this.selectedDates.push(dates[i]);
527.        }
528.    }
529.    if(redraw != false) {//redraw  the calendar if "redraw" is false or undefined
530.        this.reDraw();
531.    }
532.};
533.//-----------------------------------------------------------------------------
534.Epoch.prototype.removeDates = function (dates,redraw)  //PUBLIC: adds the dates to the calendars selectedDates array and redraws the calendar
535.{
536.    var j;
537.    for(var i=0;i<dates.length;i++)
538.    {
539.        for(j=0;j<this.selectedDates.length;j++)
540.        {
541.            if(dates[i].getUeDay() == this.selectedDates[j].getUeDay()) { //search for the dates in the selectedDates array, removing them if the dates match
542.                this.selectedDates.splice(j,1);
543.            }
544.        }
545.    }
546.    if(redraw != false) { //redraw  the calendar if "redraw" is false or undefined
547.        this.reDraw();
548.    }
549.};
550.//-----------------------------------------------------------------------------
551.Epoch.prototype.outputDate = function (vDate, vFormat) //PUBLIC: outputs a date in the appropriate format (DEPRECATED)
552.{
553.    var vDay            = this.addZero(vDate.getDate());
554.    var vMonth          = this.addZero(vDate.getMonth() + 1);
555.    var vYearLong       = this.addZero(vDate.getFullYear());
556.    var vYearShort      = this.addZero(vDate.getFullYear().toString().substring(3,4));
557.    var vYear           = (vFormat.indexOf('yyyy') > -1 ? vYearLong : vYearShort);
558.    var vHour           = this.addZero(vDate.getHours());
559.    var vMinute         = this.addZero(vDate.getMinutes());
560.    var vSecond         = this.addZero(vDate.getSeconds());
561.    return vFormat.replace(/dd/g, vDay).replace(/mm/g, vMonth).replace(/y{1,4}/g, vYear).replace(/hh/g, vHour).replace(/nn/g, vMinute).replace(/ss/g, vSecond);
562.};
563.//-----------------------------------------------------------------------------
564.Epoch.prototype.updatePos = function (target) //PUBLIC: moves the calendar's position to target's location (popup mode only)
565.{
566.    this.calendar.style.top = this.getTop(target) + this.topOffset + 'px'
567.    this.calendar.style.left = this.getLeft(target) + this.leftOffset + 'px'
568.}
569.//-----------------------------------------------------------------------------
570. 
571./*****************************************************************************/
572.function CalHeading(owner,tableCell,dow)
573.{
574.    this.owner = owner;
575.    this.tableCell = tableCell;
576.    this.dayOfWeek = dow;
577.     
578.    //the event handlers
579.    this.tableCell.onclick = this.onclick;
580.}
581.//-----------------------------------------------------------------------------
582.CalHeading.prototype.onclick = function ()
583.{
584.    //reduce indirection:
585.    var owner = this.headObj.owner;
586.    var sdates = owner.selectedDates;
587.    var cells = owner.cells;
588.     
589.    owner.cols[this.headObj.dayOfWeek] = !owner.cols[this.headObj.dayOfWeek];
590.    for(var i=0;i<cells.length;i++) //cycle through all the cells in the calendar, selecting all cells with the same dayOfWeek as this heading
591.    {
592.        if(cells[i].dayOfWeek == this.headObj.dayOfWeek && (!owner.selCurMonthOnly || cells[i].date.getMonth() == owner.displayMonth && cells[i].date.getFullYear() == owner.displayYear)) //if the cell's DoW matches, with other conditions
593.        {
594.            if(owner.cols[this.headObj.dayOfWeek])      //if selecting, add the cell's date to the selectedDates array
595.            {
596.                if(owner.selectedDates.arrayIndex(cells[i].date) == -1) { //if the date isn't already in the array
597.                    sdates.push(cells[i].date);
598.                }
599.            }
600.            else                                        //otherwise, remove it
601.            {
602.                for(var j=0;j<sdates.length;j++)
603.                {
604.                    if(cells[i].dayOfWeek == sdates[j].getDay())
605.                    {
606.                        sdates.splice(j,1); //remove dates that are within the displaying month/year that have the same day of week as the day cell
607.                        break;
608.                    }
609.                }
610.            }
611.            cells[i].selected = owner.cols[this.headObj.dayOfWeek];
612.        }
613.    }
614.    owner.reDraw();
615.};
616./*****************************************************************************/
617.function WeekHeading(owner,tableCell,week,row)
618.{
619.    this.owner = owner;
620.    this.tableCell = tableCell;
621.    this.week = week;
622.    this.tableRow = row;
623.    this.tableCell.setAttribute('class','wkhead');
624.    this.tableCell.setAttribute('className','wkhead'); //<iehack>
625.    //the event handlers
626.    this.tableCell.onclick = this.onclick;
627.}
628.//-----------------------------------------------------------------------------
629.WeekHeading.prototype.onclick = function ()
630.{
631.    //reduce indirection:
632.    var owner = this.weekObj.owner;
633.    var cells = owner.cells;
634.    var sdates = owner.selectedDates;
635.    var i,j;
636.    owner.rows[this.weekObj.tableRow] = !owner.rows[this.weekObj.tableRow];
637.    for(i=0;i<cells.length;i++)
638.    {
639.        if(cells[i].tableRow == this.weekObj.tableRow)
640.        {
641.            if(owner.rows[this.weekObj.tableRow] && (!owner.selCurMonthOnly || cells[i].date.getMonth() == owner.displayMonth && cells[i].date.getFullYear() == owner.displayYear)) //match all cells in the current row, with option to restrict to current month only
642.            {
643.                if(owner.selectedDates.arrayIndex(cells[i].date) == -1) {//if the date isn't already in the array
644.                    sdates.push(cells[i].date);
645.                }
646.            }
647.            else                                        //otherwise, remove it
648.            {
649.                for(j=0;j<sdates.length;j++)
650.                {
651.                    if(sdates[j].getTime() == cells[i].date.getTime())  //this.weekObj.tableRow && sdates[j].getMonth() == owner.displayMonth && sdates[j].getFullYear() == owner.displayYear)
652.                    {
653.                        sdates.splice(j,1); //remove dates that are within the displaying month/year that have the same day of week as the day cell
654.                        break;
655.                    }
656.                }
657.            }
658.        }
659.    }
660.    owner.reDraw();
661.};
662./*****************************************************************************/
663.//-----------------------------------------------------------------------------
664.function CalCell(owner,tableCell,dateObj,row)
665.{
666.    this.owner = owner;     //used primarily for event handling
667.    this.tableCell = tableCell;             //the link to this cell object's table cell in the DOM
668.    this.cellClass;         //the CSS class of the cell
669.    this.selected = false//whether the cell is selected (and is therefore stored in the owner's selectedDates array)
670.    this.date = new Date(dateObj);
671.    this.dayOfWeek = this.date.getDay();
672.    this.week = this.date.getWeek();
673.    this.tableRow = row;
674.     
675.    //assign the event handlers for the table cell element
676.    this.tableCell.onclick = this.onclick;
677.    this.tableCell.onmouseover = this.onmouseover;
678.    this.tableCell.onmouseout = this.onmouseout;
679.     
680.    //and set the CSS class of the table cell
681.    this.setClass();
682.}
683.//-----------------------------------------------------------------------------
684.CalCell.prototype.onmouseover = function () //replicate CSS :hover effect for non-supporting browsers <iehack>
685.{
686.    this.setAttribute('class',this.cellClass + ' hover');
687.    this.setAttribute('className',this.cellClass + ' hover');
688.};
689.//-----------------------------------------------------------------------------
690.CalCell.prototype.onmouseout = function () //replicate CSS :hover effect for non-supporting browsers <iehack>
691.{
692.    this.cellObj.setClass();
693.};
694.//-----------------------------------------------------------------------------
695.CalCell.prototype.onclick = function ()
696.{
697.    //reduce indirection:
698.    var cell = this.cellObj;
699.    var owner = cell.owner;
700.    if(!owner.selCurMonthOnly || cell.date.getMonth() == owner.displayMonth && cell.date.getFullYear() == owner.displayYear)
701.    {
702.        if(owner.selectMultiple == true//if we can select multiple cells simultaneously, add the currently selected cell's date to the selectedDates array
703.        {
704.            if(!cell.selected) //if this cell has been selected
705.            {
706.                if(owner.selectedDates.arrayIndex(cell.date) == -1) {
707.                    owner.selectedDates.push(cell.date);
708.                }
709.            }
710.            else       
711.            {
712.                var tmp = owner.selectedDates; // to reduce indirection
713.                //if the cell has been deselected, remove it from the owner calendar's selectedDates array
714.                for(var i=0;i<tmp.length;i++)
715.                {
716.                    if(tmp[i].getUeDay() == cell.date.getUeDay()) {
717.                        tmp.splice(i,1);
718.                    }
719.                }
720.            }
721.        }
722.        else //if we can only select one cell at a time
723.        {
724.            owner.selectedDates = new Array(cell.date);
725.            if(owner.tgt) //if there is a target element to place the value in, do so
726.            {
727.                owner.tgt.value = owner.selectedDates[0].dateFormat();
728.                if(owner.mode == 'popup') {
729.                    owner.hide();
730.                }
731.            }
732.        }
733.        owner.reDraw(); //redraw the calendar cell styles to reflect the changes
734.    }
735.};
736.//-----------------------------------------------------------------------------
737.CalCell.prototype.setClass = function ()  //private: sets the CSS class of the cell based on the specified criteria
738.{
739.    if(this.selected) {
740.        this.cellClass = 'cell_selected';
741.    }
742.    else if(this.owner.displayMonth != this.date.getMonth() ) {
743.        this.cellClass = 'notmnth';
744.    }
745.    else if(this.date.getDay() > 0 && this.date.getDay() < 6) {
746.        this.cellClass = 'wkday';
747.    }
748.    else {
749.        this.cellClass = 'wkend';
750.    }
751.     
752.    if(this.date.getFullYear() == this.owner.curDate.getFullYear() && this.date.getMonth() == this.owner.curDate.getMonth() && this.date.getDate() == this.owner.curDate.getDate()) {
753.        this.cellClass = this.cellClass + ' curdate';
754.    }
755. 
756.    this.tableCell.setAttribute('class',this.cellClass);
757.    this.tableCell.setAttribute('className',this.cellClass); //<iehack>
758.};
759./*****************************************************************************/
760.Date.prototype.getDayOfYear = function () //returns the day of the year for this date
761.{
762.    return parseInt((this.getTime() - new Date(this.getFullYear(),0,1).getTime())/86400000 + 1);
763.};
764.//-----------------------------------------------------------------------------
765.Date.prototype.getWeek = function () //returns the day of the year for this date
766.{
767.    return parseInt((this.getTime() - new Date(this.getFullYear(),0,1).getTime())/604800000 + 1);
768.};
769./*function getISOWeek()
770.{
771.    var newYear = new Date(this.getFullYear(),0,1);
772.    var modDay = newYear.getDay();
773.    if (modDay == 0) modDay=6; else modDay--;
774.     
775.    var daynum = ((Date.UTC(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0) - Date.UTC(this.getFullYear()),0,1,0,0,0)) /1000/60/60/24) + 1;
776.     
777.    if (modDay < 4 ) {
778.        var weeknum = Math.floor((daynum+modDay-1)/7)+1;
779.    }
780.    else {
781.        var weeknum = Math.floor((daynum+modDay-1)/7);
782.        if (weeknum == 0) {
783.            year--;
784.            var prevNewYear = new Date(this.getFullYear(),0,1);
785.            var prevmodDay = prevNewYear.getDay();
786.            if (prevmodDay == 0) prevmodDay = 6; else prevmodDay--;
787.            if (prevmodDay < 4) weeknum = 53; else weeknum = 52;
788.        }
789.    }
790.     
791.    return + weeknum;
792.}*/
793.//-----------------------------------------------------------------------------
794.Date.prototype.getUeDay = function () //returns the number of DAYS since the UNIX Epoch - good for comparing the date portion
795.{
796.    return parseInt(Math.floor((this.getTime() - this.getTimezoneOffset() * 60000)/86400000)); //must take into account the local timezone
797.};
798.//-----------------------------------------------------------------------------
799.Date.prototype.dateFormat = function(format)
800.{
801.    if(!format) { // the default date format to use - can be customized to the current locale
802.        format = 'd/m/Y';
803.    }
804.    LZ = function(x) {return(x < 0 || x > 9 ? '' : '0') + x};
805.    var MONTH_NAMES = new Array('ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.','ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.');
806.    var DAY_NAMES = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
807.    format = format + "";
808.    var result="";
809.    var i_format=0;
810.    var c="";
811.    var token="";
812.    var y=this.getFullYear().toString();
813.    var M=this.getMonth()+1;
814.    var d=this.getDate();
815.    var E=this.getDay();
816.    var H=this.getHours();
817.    var m=this.getMinutes();
818.    var s=this.getSeconds();
819.    var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
820.    // Convert real this parts into formatted versions
821.    var value = new Object();
822.    //if (y.length < 4) {y=''+(y-0+1900);}
823.    value['Y'] = y.toString();
824.    value['y'] = y.substring(2);
825.    value['n'] = M;
826.    value['m'] = LZ(M);
827.    value['F'] = MONTH_NAMES[M-1];
828.    value['M'] = MONTH_NAMES[M+11];
829.    value['j'] = d;
830.    value['d'] = LZ(d);
831.    value['D'] = DAY_NAMES[E+7];
832.    value['l'] = DAY_NAMES[E];
833.    value['G'] = H;
834.    value['H'] = LZ(H);
835.    if (H==0) {value['g']=12;}
836.    else if (H>12){value['g']=H-12;}
837.    else {value['g']=H;}
838.    value['h']=LZ(value['g']);
839.    if (H > 11) {value['a']='pm'; value['A'] = 'PM';}
840.    else { value['a']='am'; value['A'] = 'AM';}
841.    value['i']=LZ(m);
842.    value['s']=LZ(s);
843.    //construct the result string
844.    while (i_format < format.length) {
845.        c=format.charAt(i_format);
846.        token="";
847.        while ((format.charAt(i_format)==c) && (i_format < format.length)) {
848.            token += format.charAt(i_format++);
849.            }
850.        if (value[token] != null) { result=result + value[token]; }
851.        else { result=result + token; }
852.        }
853.    return result;
854.};
855./*****************************************************************************/
856.Array.prototype.arrayIndex = function(searchVal,startIndex) //similar to array.indexOf() - created to fix IE deficiencies
857.{
858.    startIndex = (startIndex != null ? startIndex : 0); //default startIndex to 0, if not set
859.    for(var i=startIndex;i<this.length;i++)
860.    {
861.        if(searchVal == this[i]) {
862.            return i;
863.        }
864.    }
865.    return -1;
866.};
867./*****************************************************************************/




Tag : JavaScript, jQuery



ประวัติการแก้ไข
2012-05-20 14:52:51
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-05-20 14:49:19 By : lala_freedomtime View : 1963 Reply : 4
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

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

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

Quote:
this.yearSelect


ลองบวบก 543 เข้าไปครับ

parseInt(this.yearSelect) + 543
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-21 06:13:30 By : mr.win
 

 

No. 2



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



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


ยังไม่ได้เลยอ่ะครับ ไม่มีอะไรเปลี่ยนแปลงเลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-21 09:39:31 By : lala_freedomtime
 

 

No. 3



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

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

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

ผมไม่แน่ใจว่ามันบวกตรงไหนครับ คุณจะต้องหาให้เจอน่ะครับ เพราะมันมีหลายบรรทัดเกิน ดูแล้วตาลาย ลายตา
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-21 20:41:54 By : mr.win
 

 

No. 4



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



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


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-07-12 11:31:07 By : KT-Revenue
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รับค่าจากปฏิทินลง textbox แต่อยากแก้จากปี คศ เป็นปี พศ อ่ะครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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