|
 |
|
มีวิธีเขียนโค้ดอันนี้ให้สั้นลงไหมค่ะ พอดีว่า ใช้ปฏิทิน ที่คลิกแล้วขึ้นให้เลือกหน่ะค่ะ แต่ว่า 1 เพจมันมีหลาย textbox ที่้้ต้องใ้ช้ปฏิทินวันที่หน่ะค่ะ อยากเขียนให้สั้นกว่านี้ค่ะมันดูเยอะไป ^w^ |
|
 |
|
|
 |
 |
|
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.1.offset.datepicker.min.js"></script>
<script type="text/javascript">
$(function(){
// Datepicker
$("#date_make").datepicker({ dateFormat: 'yy-mm-dd'});
$("#date_make").datepicker('option','monthNames',['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']);
$("#date_make").datepicker('option','dayNamesMin',['อา','จ.','อ.','พ.','พฤ','ศ.','ส.']);
$("#start_evaluation").datepicker({ dateFormat: 'yy-mm-dd'});
$("#start_evaluation").datepicker('option','monthNames',['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']);
$("#start_evaluation").datepicker('option','dayNamesMin',['อา','จ.','อ.','พ.','พฤ','ศ.','ส.']);
$("#end_evaluation").datepicker({ dateFormat: 'yy-mm-dd'});
$("#end_evaluation").datepicker('option','monthNames',['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']);
$("#end_evaluation").datepicker('option','dayNamesMin',['อา','จ.','อ.','พ.','พฤ','ศ.','ส.']);
<!-- $("#inline").datepicker({ dateFormat: 'dd/mm/yy', inline: true });-->
});
</script>
<style type="text/css">
/*demo page css*/
body{ font: 80% "Trebuchet MS", sans-serif; margin: 50px;}
.demoHeaders { margin-top: 2em; }
#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
ul#icons {margin: 0; padding: 0;}
ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left; list-style: none;}
ul#icons span.ui-icon {float: left; margin: 0 4px;}
ul.test {list-style:none; line-height:30px;}
</style>
<style type="text/css">
<!--
.style2 {color: #000000}
.style3 {
color: #FF0000;
font-weight: bold;
}
.style4 {color: #FF0000}
.style5 {color: #0000FF}
-->
</style>
<link href="../css/ui-lightness/jquery-ui-1.8.1.custom.css" rel="stylesheet" type="text/css" />
ส่วน input form ที่เรียกใช้ปฏิทินหน่ะค่ะ จะใช้ name เดียวกันก็ไม่ได้เพราะต้องนำค่าไปใช้ต่อ
<input type="text" id="date_make" name="date_make" />
<input type="text" name="start_evaluation" id="start_evaluation" />
<input type="text" name="end_evaluation" id="end_evaluation" />
ตรงส่วนโค้ดที่ทำตัวหนาหน่ะค่ะ มันดูเยอะไปนิดนึง อยากรู้ค่ะว่าสามารถเขียนให้สั้นกว่านี้ได้ไหม ขอบคุณค่ะ
Tag : PHP, MySQL, jQuery

|
|
 |
 |
 |
 |
Date :
2010-12-02 16:12:06 |
By :
nuie |
View :
1280 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ลองสร้างตัวแปรขึ้นมาเก็บค่า option สิครับ เวลาแก้ไขจะได้แกไขแค่ครั้งเดียว จะช่วยลด code ลงได้หน่อย
เช่น
Code (JavaScript)
var option1 = "{ dateFormat: 'yy-mm-dd'}";
$("#date_make").datepicker(option1);
|
 |
 |
 |
 |
Date :
2010-12-02 16:20:38 |
By :
injustiz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ คุณ InjustiZ นะค่ะ
ได้ลองนำแนวคิดไปเขียนโค้ดดังนี้ค่ะ ใช่อย่างที่คุณแนะนำเปล่าน้า คือไม่ถนัด javascript หน่ะค่ะ
<script type="text/javascript">
$(function(){
// Datepicker
var option1 = "{ dateFormat: 'yy-mm-dd'}";
var option2 = "'option','monthNames',['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']";
var option3 = "'option','dayNamesMin',['อา','จ.','อ.','พ.','พฤ','ศ.','ส.']";
$("#date_make").datepicker(option1);
$("#date_make").datepicker(option2);
$("#date_make").datepicker(option3);
<!-- $("#inline").datepicker({ dateFormat: 'dd/mm/yy', inline: true });-->
});
</script>
แล้วตรง input form ก็
<input type="text" id="date_make" name="date_make" />
แต่พอรันดู คลิกตรง textbox date_make แล้วกลายเป็นว่าปฏิทินหายไปหน่ะค่ะ ไม่ขึ้นเลย จากตอนแรกมันจะเรียกเป็นปฏิทิน
หน้าตาสวยๆหนะ่ค่ะ แอบสงสัยว่าเขียนผิดตรงไหนหรือเปล่า ขอบคุณนะค่ะ
|
 |
 |
 |
 |
Date :
2010-12-02 17:53:08 |
By :
nuie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|