2011-04-11 205 views
0

我期待創建一個動態的JavaScript倒數計時器,我想從我的SQL服務器數據庫中傳遞一個日期時間變量,並讓它倒數到這個日期然後顯示一條消息,我已經試過幾乎所有的jQuery插件,我可以找到和沒去過能夠編輯他們做什麼,我需要,我還需要能夠具有相同的頁面上有多個倒計時定時器,創建一個動態的JavaScript倒數計時器

任何幫助將大大appriciated

Cheers

Scott

======= =======編輯

多試錯我能修改此之後的js http://andrewu.co.uk/clj/countdown/pro/

做什麼,我需要

+7

如果你希望有人爲你寫這個,你將不得不提供更詳細的要求和建立一個支付方案。如果您嘗試過某種方法時遇到問題,那麼您應該發佈相關問題的代碼。 – Pointy 2011-04-11 14:57:10

+0

是的,這將是一個更好的方法,我有點寫這個,因爲我正在離開工作,在經過多次試驗和錯誤後,我設法修改這個http://andrewu.co.uk/clj/countdown/pro /做我需要的東西 – Scott 2011-04-12 10:50:29

+0

你能以一種能夠幫助他人的方式回答你自己的問題嗎?如果你這樣做,你可以選擇你的正確答案。這看起來很奇怪,但它是處理這種情況的首選方式。 – Will 2011-04-12 19:02:24

回答

0

試試這個:因此

function Thick(startin) { 
    startin--; 
    document.getElementById('timer').innerHTML = startin; 
    if(startin > 0) setTimeout('Thick(' + startin + ')', 1000); 
} 

通話功能在身體的onLoad,如:

<body onLoad="Thick(20);"> 

希望ŧ他的幫助:)

0
//TODAY'S DATE 
$today = time(); 
//FETCHES DATE AND TIME FOR THE EVENT FROM DATABASE 

$sql = "SELECT * FROM post"; 
$result = mysqli_query($conn, $sql); 
if (mysqli_num_rows($result) > 0) { 
$Row = (mysqli_fetch_assoc($result)); 
$th = $Row['endtime'];  
} 
echo $th 

first of all put it into a variable then use your javascript to call the variable 

//let get todays date here 
var today = new Date(); 
var DD = today.getDate(); 
var MM = today.getMonth()+1; //January is 0! 
var YYYY = today.getFullYear(); 
//let get the Difference in Sec btw the two dates 
var _DateFromDBProgEndDate = '<?php echo $th; ?>'; 
var ProgEndTime = new Date(_DateFromDBProgEndDate); 
var TodayTime = new Date(); 

var differenceTravel = ProgEndTime.getTime()- TodayTime.getTime() ; 
var seconds = Math.floor((differenceTravel)/(1000)); 
//////////////////////////////// 
var SecDiffFromToday = seconds; 
var seconds = SecDiffFromToday; 
function timer() { 
    var days  = Math.floor(seconds/24/60/60); 
    var hoursLeft = Math.floor((seconds) - (days*86400)); 
    var hours  = Math.floor(hoursLeft/3600); 
    var minutesLeft = Math.floor((hoursLeft) - (hours*3600)); 
    var minutes  = Math.floor(minutesLeft/60); 
    var remainingSeconds = seconds % 60; 
    if (remainingSeconds < 10) { 
     remainingSeconds = "0" + remainingSeconds; 
    } 
    document.getElementById('countdown').innerHTML = days + ":" + hours + ":" + minutes + ":" + remainingSeconds; 
    if (seconds == 0) { 
     clearInterval(countdownTimer); 
     document.getElementById('countdown').innerHTML = "Completed"; 
    } else { 
     seconds--; 
    } 
} 
var countdownTimer = setInterval('timer()', 1000); 
</script> 


the javascript call in the variable with '<?php echo $th; ?>'; then the javascript does the count down with out refreshing the page