2017-03-01 23 views
-1

我正在爲婚禮活動建立一個簡單的網頁。假設我需要顯示倒數計時,並且想要從輸入表單開始計算日期。我一直在使用谷歌搜索,我已經看到了一些有趣的代碼,但已經很晚了,我的眼睛和頭腦都非常疲憊。這是我的代碼...如何從datepicker表單輸入開始jquery倒計時?

<?php $date = date('2017/05/21'); // this value supossed to be taken from a form.?> 
<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
<div id="clock"></div> 
</body> 
</html> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
<script src="http://www.testingserver.dev/template/assets/web/assets/jquery/jquery.countdown.min.js"></script> 
<script> 
var eventdate = new Date("<?php echo $date; ?>"); // I'm trying to use a php variable in jquery. 
$('#clock').countdown('eventdate', function(event) { 
var $this = $(this).html(event.strftime('' 
//+ '<div style="background-color: #ffcc00; width: 25%;"><p>Weeks<br>%w</p></div> ' 
+ '<span>%D</span> days ' 
+ '<span>%H</span> hrs ' 
+ '<span>%M</span> min ' 
+ '<span>%S</span> sec')); 
}); 
</script> 
+0

207/05/21''複製/粘貼錯誤?或者你真的有'207'作爲你的年值? – Sean

+0

另外,我不認爲在jQuery UI中有'倒計時',那麼這個函數的來源是什麼?是否有一個原因,'eventdate''在引號中,作爲一個字符串,而不是沒有作爲K的var? – Sean

+0

是一個複製/粘貼錯誤,樣本日期是2017/05/21,但它被推遲以獲得此值dinamically。 Thaks注意到了,@Sean – KAZZABE

回答

1

我想這是鏈接到圖書館網站 - http://hilios.github.io/jQuery.countdown/

你傳遞字符串'eventdate'countdown()方法,但它預計將有效日期。所以只要刪除撇號,你會得到eventdate變量的值:

$('#clock').countdown(eventdate, function(event) { 
    // ... 
} 
+0

做到了,它的工作。謝啦!現在我可以去睡覺了。 @PetrHejda – KAZZABE