我有这段代码片段,当我的$remainingTime
变为零时,我希望它在回调中运行停止功能。我不知道在else语句中我要写什么。
var clock = $('.clock').FlipClock(
<?php
$now = new DateTime('now');
$tm = new DateTime('2017-12-22 12:00:00');
$remainingTime = $tm->getTimestamp()-$now->getTimestamp();
if($remainingTime>0) {
echo $remainingTime;
} else {
}
?>
,{
clockFace: 'DailyCounter',
countdown: true,
callbacks: {
stop: function() {
$(".timerContainer").css('display','none');
}
}
});
答案 0 :(得分:0)
您只需使用setInterval
并计算,直至到达您的时间:
例如,一段运行10秒的代码片段:
var i = 10;
var end = 15;
var statusDiv = document.getElementById("status");
var t = setInterval(function(){
if(i++ >= end) {
clearInterval(t);
stop();
}
statusDiv.innerHTML = i;
}, 1000);
function stop(){
alert("stopped, Now 'i' equals " + i);
}
<div id="status"></div>
我不确定FlipClock
正在做什么,但它似乎就像一个计数器,但这里是如何做与你在PHP中所做的相同,这是不需要的,如果你想得到日期和在JavaScript中进行日期减法,请查看以下代码段:
var d1 = new Date(); //"now"
var d2 = new Date("December 23, 2017 01:13:00") // some date
//var d2= new Date(2017,12,23,1,13,0);//same as d2 above
var remainingTime = Math.abs(d1-d2); // get the diff in milliseconds
答案 1 :(得分:0)
在插件代码之后进行检查。
var clock = $('.clock').FlipClock(
<?php
$now = new DateTime('now');
$tm = new DateTime('2017-12-22 12:00:00');
$remainingTime = $tm->getTimestamp()-$now->getTimestamp();
if($remainingTime>0) {
echo $remainingTime;
} else {
}
?>
,{
clockFace: 'DailyCounter',
countdown: true,
callbacks: {
stop: function() {
$(".timerContainer").css('display','none');
}
}
});
<?php if ($remainingTime == 0) {
?>
$(".timerContainer").hide();
<?php }
答案 2 :(得分:0)
我不会那样混合JS和PHP。你可以这样做:
from tkinter import *
def newwindow():
newwindow = Tk()
newwindow.title('Sign Up')
newwindow.geometry('200x400')
def sign_done():
david = a.get()
javed = b.get()
lbee = Label(newwindow, text=david).pack()
baeee = Label(newwindow, text=javed).pack()
a = StringVar()
b = StringVar()
user = Entry(newwindow, textvariable=a).pack()
pword = Entry(newwindow, textvariable=b).pack()
done = Button(newwindow, text='done now', command=sign_done).pack()
newwindow.mainloop()
root = Tk()
root.title('Gulmeena')
root.geometry("500x200")
button = Button(root, text='Go', command=newwindow).pack()
root.mainloop()