[請益] IE8 Javascript錯誤 php(解決了
這是我的程式片段
<?
echo "<script language='JavaScript'>";
?>
var DifferenceHour = -1
var DifferenceMinute = -1
var DifferenceSecond = -1
var Tday = new Date(<? echo "'".$nm." ".$nd.",".$ny." ".$time.":00:00'"; ?>)
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000
function clock()
{
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var timevalue = ""+((hour > 12) ? hour-12:hour)
timevalue +=((minute < 10) ? ":0":":")+minute
timevalue +=((second < 10) ? ":0":":")+second
timevalue +=((hour >12 ) ? " PM":" AM")
// document.formnow.now.value = timevalue
var convertHour = DifferenceHour
var convertMinute = DifferenceMinute
var convertSecond = DifferenceSecond
var Diffms = Tday.getTime() - time.getTime()
DifferenceHour = Math.floor(Diffms / daysms)
Diffms -= DifferenceHour * daysms
DifferenceMinute = Math.floor(Diffms / hoursms)
Diffms -= DifferenceMinute * hoursms
DifferenceSecond = Math.floor(Diffms / Secondms)
Diffms -= DifferenceSecond * Secondms
var dSecs = Math.floor(Diffms / microsecond)
if(convertHour != DifferenceHour) document.formnow.dd.value=DifferenceHour
if(convertMinute != DifferenceMinute)
document.formnow.hh.value=DifferenceMinute
if(convertSecond != DifferenceSecond)
document.formnow.mm.value=DifferenceSecond
document.formnow.ss.value=dSecs
//if(!DifferenceHour && !DifferenceMinute && !DifferenceSecond &&
!dSecs)window.location.reload()
// document.formnow.Tnow.value= DifferenceHour DifferenceMinute +
DifferenceSecond + dSecs
setTimeout("clock()",1000)
}
<?
echo "</script>";
?>
這樣的情況下
FF看程式碼可以正確顯示時間
並且倒數
IE8有抓到Php給的時間
卻出現NaN的狀態
目前懷疑三種可能性
1.據說連comment格式不合都有問題,可是我把comment全刪了還是有問題
2.據說setTimeout跟IE8有點不相容
3.據說header我宣告成UTF-8 也可能會有IE問題
請問怎麼解決
--
▼▼
/﹊ ﹚
— //‘ \ ╲ ◥◣
── ノ /◤▃▄▄▄◣ █ 川澄 舞˙兔子mode
— ~ ︶◢◣▄ ◢◤ @binshaunMKII
﹊ ▼◤
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.206.43
推
04/27 10:40, , 1F
04/27 10:40, 1F
不好意思因為使用的編輯器不這樣做的話,js中的php會沒有標示色
我以為這樣會失效,剛剛試過一次可以正常執行
補充問題
現在發現似乎不是上面的問題
NaN的原因是計算上有錯誤(IE沒抓到值
var Tday = new Date(<? echo '"'.$nm.' '.$nd.', '.$ny.' '.$time.':00:00"'; ?>)
這是我JS中的某一行
source的結果是
var Tday = new Date("05 04, 2011 6:00:00")
FF可以正常抓到值
並且帶入JS中
可是IE8雖然有正確出現在source碼
卻無法帶入JS
請問怎麼解決?
我會這樣確認是因為我把欄位暫時顯示現在時間
發現其實是可以正常運作的
也就是算差值時有錯
把php直接用字串取代就可以運作了
可見得php帶入有問題
※ 編輯: KawasumiMai 來自: 61.62.206.43 (04/27 10:52)
→
04/27 11:16, , 2F
04/27 11:16, 2F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章