0
我通過jQuery獲取當前時間,然後根據時間顯示/隱藏商店開放標誌。在分鐘前添加0 1-9
我的當前代碼運行良好,除了當時間爲0-9分鐘時,在這種情況下,它會失敗並錯誤地顯示CLOSED語句。原因是,該時間被呈現爲例如119 11:09 - 我需要什麼就寫爲1109,而不是119
代碼是:
tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
function GetClock(){
var d=new Date();
var jwdday=d.getDay(),ap;
var jwdtime = d.getHours() + "" + d.getMinutes(),gp;
/* sign logic */
if (jwdday != "0") {
if((jwdtime < 1800 && jwdtime >= 1400) || (jwdtime < 1300 && jwdtime >= 700)) {
document.getElementById('signStatus').innerHTML="<img src='http://www.hawkesbury-stores.co.uk/wp-content/themes/HawkSOS/images/core/weareOpen.png' alt='We are currently OPEN' title='We are currently OPEN' class='weareOpen'>";
}
else {
document.getElementById('signStatus').innerHTML="<img src='weareClosed.png' alt='We are currently CLOSED' title='We are currently CLOSED' class='weareClosed'>";
}
}
else if(jwdtime < 1230 && jwdtime >= 700){
document.getElementById('signStatus').innerHTML="<img src='weareOpen.png' alt='We are currently OPEN' title='We are currently OPEN' class='weareOpen'>";
}
else {
document.getElementById('signStatus').innerHTML="<img src='weareClosed.png' alt='We are currently CLOSED' title='We are currently CLOSED' class='weareClosed'>";
}
}
window.onload=function(){
GetClock();
setInterval(GetClock,1000);
}
'變種分鐘=分鐘> 10?分鐘:「0」+分鐘;'這樣的東西 – guradio
謝謝 - 是的,這種方法奏效。 – dubbs