gpt4 book ai didi

javascript - 钛自动更新剩余时间标签

转载 作者:行者123 更新时间:2023-11-28 19:51:35 24 4
gpt4 key购买 nike

我正在尝试在 Titanium 开发的 Android 应用程序中创建一个标签,该标签会根据我的输入自动更新剩余时间(从当前日期到 2014 年 5 月 30 日)。我使用 JavaScript 创建了以下倒计时函数:

var current = 'Today is the day!';
var montharray = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function countdown(yr,m,d){
theyear = yr;
themonth = m;
theday = d;
var today = new Date();
var todayy = today.getYear();
var todaym = today.getMonth();
var todayd = today.getDate();
var todayh = today.getHours();
var todaymin = today.getMinutes();
var todaysec = today.getSeconds();
var todaystring = montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
futurestring = montharray[m-1]+" "+d+", "+yr;
dd = Date.parse(futurestring) - Date.parse(todaystring);
dday = Math.floor(dd/(60*60*1000*24)*1);
dhour = Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
dmin = Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
dsec = Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if (dday==0 && dhour==0 && dmin==0 && dsec==1){
homeLabel6.text = current;
return;
} else {
homeLabel6.text = dday + 'd:'+ dhour + 'h:' + dmin + 'm:' + dsec + 's';
setTimeout('countdown(theyear,themonth,theday)',1000);
}
}
countdown(2014,05,30);

不幸的是,当我在手机上构建应用程序时,我收到以下错误:

[ERROR] :  TiApplication: (KrollRuntimeThread) [821,821] Sending event: exception on thread: KrollRuntimeThread msg:java.lang.IncompatibleClassChangeError: interface not implemented; Titanium 3.2.2,2014/03/05 12:22,96e9a07
[ERROR] : TiApplication: java.lang.IncompatibleClassChangeError: interface not implemented
[ERROR] : TiApplication: at ti.modules.titanium.TitaniumModule$Timer.run(TitaniumModule.java:152)
[ERROR] : TiApplication: at android.os.Handler.handleCallback(Handler.java:615)
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:92)
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:137)
[ERROR] : TiApplication: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)

如果有人可以向我解释一下,为了使这项工作正常进行,不兼容的地方在哪里,那就太好了。我只想要一个标签显示这一点,没有开始/停止按钮或类似的东西。就像上面代码 fragment 中提到的那样,我想要信息的标签称为:homeLabel6。我也尝试过其他选项,但似乎都不适合我的需求。

最佳答案

setTimeout 方法采用函数和持续时间,并且您传递字符串来代替函数 setTimeout('countdown(theyear,themonth,theday)',1000);

试试这个:

setTimeout(函数(){
倒计时(年、月、日);
},1000);

或者如果您想每 1 秒更新一次文本,也可以使用 setInterval ,如下所示:setInterval(函数(){
倒计时(年、月、日);
},1000);

关于javascript - 钛自动更新剩余时间标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23364332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com