我有一个jquery函数,在使用wordpress中的表单输入日期时倒计时。它会罚款,但我希望包含一项功能,如果没有包含日期,则该日期为当前日期。我该如何添加?
jQuery(function($){
// set the date we're counting down to
var target_date = new Date( '<?php $user_id = get_current_user_id(); $key = 'Your Date'; $single = true; $user_last = get_user_meta( $user_id, $key, $single ); echo $user_last; ?>'' ).getTime();
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById("ribboncountdown");
var days_span = document.createElement("SPAN");
days_span.className = 'days';
countdown.appendChild(days_span);
// update the tag with id "countdown" every 1 second
setInterval(function () {
// find the amount of "seconds" between now and target
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;
// do some time calculations
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
// format countdown string + set tag value.
if (days < 0) {
days_span.innerHTML = '<span>' + days * -1 + '</span>' + ' days since';
}
else {
days_span.innerHTML = '<span>' + days + '</span>' + ' days to go';
}
//ribboncountdown.innerHTML = days + "d,;
}, 1000);
});