|
 |
|
ทำไมโค๊ดฟังก์ชั่น LastUpdate ไม่ทำงานถูกต้องใน .php แต่ .html ได้ล่ะ |
|
 |
|
|
 |
 |
|
เรียน พี่ ๆ ทุกท่าน
โค๊ดด้านล่างนี้ จะเป็นโค๊ดฟังก์ชั่น JavaScript เกี่ยวกับ LastUpdate คือว่า
มันจะแสดงวันเดือนปี เวลา ที่เราแก้ไขไฟล์นั้น ๆ เช่น หากเราแก้ไขไฟล์ .html นั้นแล้ว
พอเอาไปเปิดบนเว็บ โดยปกติจะแสดงวันเดือนปี เวลา ที่เราแก้ไขไฟล์นั้นไป
แต่ผมมีปัญหาที่ว่า พอเอาไปแสดงบนไฟล์ .php แล้วเอาไปเปิดบนเว็บ มันจะแสดง
วันเดือน ปี เวลา ณ ขณะนั้น (หากกดปุ่ม F5 หรือปุ่ม refresh มันก็จะแสดงวันเดือนปี เวลา ณ ขณะนั้นเลย)
ซึ่งไม่ถูกต้อง เพราะไม่ใช่วันเดือนปี เวลา ที่เราแก้ไขไฟล์นั้นจริง
แต่พอให้เป็นไฟล์ .html มันแสดงวันเดือนปี เวลา ที่เราแก้ไขนั้นอย่างถูกต้อง...
ผมอยากทราบว่าเราจะแก้ไขอย่างไร หรือว่ามันไม่ทำงานบน .php หรือครับ แล้วจะสามารถหาไฟล์แบบนี้
ที่สามารถทำงานบน .php ที่ไหนได้บ้างหรือครับ ขอขอบคุณมาก ครับ..
----------------------------------
<html>
<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function getLongDateString(){
monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
dayOfWeek = this.getDay();
day = dayNames[dayOfWeek];
dateOfMonth = this.getDate();
monthNo = this.getMonth();
month = monthNames[monthNo];
year = this.getYear();
hour = this.getHours();
minute = this.getMinutes();
second = this.getSeconds();
if (year < 2000)
year = year + 1900;
dateStr = day+" "+dateOfMonth+" "+month+", "+year+" "+(hour)+":"+(minute)+":"+(second); // format date
return dateStr;
}
Date.prototype.getLongDateString=getLongDateString;
function ModiLastUpdate(){
DateTimeStr = document.lastModified;
secOffset = Date.parse(DateTimeStr);
if (secOffset == 0 || secOffset == null)
dateStr = "Unknown";
else{
aDate = new Date();
aDate.setTime(secOffset);
datestr = aDate.getLongDateString();
}
return dateStr;
}
// -->
</script>
</head>
<body>
<script anguage="JavaScript" type="text/javascript">
document.write("<center> Last Update: ");
document.writeln(ModiLastUpdate(),"</center>");
</script>
</body>
</html>
----------------------------------
มันจะแสดงบนหน้าเว็บดังนี้ : นะครับ..
Last Update: Friday 23 July, 2010 10:43:53
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-07-23 10:47:08 |
By :
riderman |
View :
1118 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้มาตอบนะครับผม....อยากจะบอกว่าผมเจอปัญหาเหมือนท่าน เป๊ะเลย.....ใช้โค๊ดตัวเดียวกันเลย...
รอผู้รู้เหมือนกันครับ
|
 |
 |
 |
 |
Date :
2010-09-22 11:09:01 |
By :
tcmetal |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|