倒计时小程序setTimeout传递参数
在我看来在倒计时中最重要的其实无非就那么几点
其一,找好逻辑关系。弄清楚是当前时间减去最后的时间倒计时还是最后的时间减去当前时间倒计时。
毫无疑问,大多数的倒计时都应该是用最后的时间减去当前时间,因为最后的时间是固定的,而当前时间在走,因此才实现倒计时。
第二,就是时间的换算,这个就是上面已经说的,很容易。
第三,其实也是最重要的就是,setTimeOut()方法的应用,我在这就算是栽了大跟头,
这个方法,是每隔一段时间,重复执行某一段函数。
function countDownTime(strP_Time){ var my_time=showTime(); my_time=(new Date(my_time)).getTime(); var dateDigitToString = function (num) { return num 10 ? '0' + num : num; }; var msg=''; var publish_time=strP_Time+18000000; var now_time=my_time; var remain_time=publish_time-my_time; var nH = dateDigitToString(Math.floor(remain_time/(1000*60*60)) % 24); var nM = dateDigitToString(Math.floor(remain_time / (1000 * 60)) % 60); var nS = dateDigitToString(Math.floor(remain_time / 1000) % 60); if(nS=0) { msg = nH+":"+nM + ":" + nS; } else { msg='00'+' '+':'+' '+'00'+' '+':'+' '+'00'; } $('.add').html(' '+' '+' '+' '+' '+'揭晓倒计时'+' '+msg); setTimeout(function(){countDownTime(strP_Time)},1000);}当setTimout()方法需要传递参数的时候
window.settimeout()方法要调用带参数的函数有两种方法:1.function init(){var url = "%=basePath%fetchwater.do?method=searchRealWater&xzqh=" + "%=xzqh%" + "&rand="+Math.random(); //alert(url); window.setTimeout(function(){ searchJDWater(url);},100);}2.function init(){var url = "%=basePath%fetchwater.do?method=searchRealWater&xzqh=" + "%=xzqh%" + "&rand="+Math.random(); //alert(url); window.setTimeout(“searchJDWater(”+url+“)”, 100);}注意: 带参数方法使用setTimeout要注意,setTimeout("函数名("+参数+")",毫秒数),这里的参数只能是字符串形式的,而不能传递一个对象
TAG标签: 微信小程序cleartimeout
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

