我想把兩個(gè)方法封裝起來(lái), 以后就可以多次使用了, 時(shí)間只能顯示一次就報(bào)錯(cuò) ? 還有fn也傳不了??是因?yàn)閟etTimeout的問(wèn)題 ?代碼:? ????<h1?id="box2"></h1>
????<input?type="button"?id="button"?value="倒計(jì)時(shí)">
????
????<script?type="text/javascript">
????????window.onload?=?function?()?{
????????????//?倒時(shí)時(shí)
????????????var?button?=?document.getElementById('button');
????????????????button.disabled?=?true;
????????????showTime().countDown('box2',function?()?{
????????????????button.disabled?=?false;
????????????});
????????????button.onclick?=?function?()?{
????????????????console.log(this);
????????????}
????????}
????????function?showTime()?{
????????????return?{
????????????????countDown:function?(id,fn)?{
????????????????????var?nowTime?=?new?Date();
????????????????????var?endTime?=?new?Date('2016/10/17,01:02:50');
????????????????????var?resultTime?=?parseInt((endTime.getTime()?-?nowTime.getTime())?/?1000);?//?毫秒?時(shí)間差
????????????????????var?d?=?parseInt(resultTime?/?(24*60*60));?//天
????????????????????var?h?=?showTime().checkTime(parseInt(resultTime?/?(60*60)?%?24));//時(shí)
????????????????????var?m?=?showTime().checkTime(parseInt(resultTime?/?60?%?60));?//分
????????????????????var?s?=?showTime().checkTime(parseInt(resultTime?%?60));//秒
????????????????????//?document.getElementById('box2').innerHTML?=?d+'天'+h+'時(shí)'+m+'分'+s+'秒';
????????????????????document.getElementById(id).innerHTML?=?d+'天'+h+'時(shí)'+m+'分'+s+'秒';
????????????????????if?(resultTime?<=?0)?{
????????????????????????fn();
????????????????????????document.getElementById(id).innerHTML?=?'End';
????????????????????}
????????????????????setTimeout(showTime().countDown,1000);
????????????????},
????????????????checkTime:function?(num)?{
????????????????????if?(num?<?10)?{
????????????????????????num?=?'0'+num;
????????????????????}
????????????????????return?num;
????????????????}
????????????}
????????}
????</script>
JS大神幫我看看, 傳參問(wèn)題, 謝謝
SuperManSuperWorld
2016-10-17 01:07:08