<script language="javascript" type="text/javascript">
var interval = 100;
function ShowCountDown(year,month,day,divname)
{
var now = new Date();
var endDate = new Date(year, month-1, day);
var leftTime=endDate.getTime()-now.getTime();
var leftsecond = parseInt(leftTime/1000);
//var day1=parseInt(leftsecond/(24*60*60*6));
var year=Math.floor(leftsecond/(60*60*24*365));
var day1=Math.floor(leftsecond/(60*60*24));
var hour=Math.floor((leftsecond-day1*24*60*60)/3600);
var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
var cc = document.getElementById(divname);
cc.innerHTML = "<h2>"+day1+"天"+hour+"小时"+minute+"分"+second+"秒"+"</h2>";
if(second.length<2)
{
second.innerHTML ="0"+second;
}
}
window.setInterval(function(){ShowCountDown(2017,1,27,'divdown1');}, interval);
</script>
是不是调用IF语句有点问题啊
var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
second.innerHTML ="0"+second; //second不是dom元素,没有innerHTML属性
这点错了,那么要如何改变?
@acfun的怨念: 直接赋值:second = "0" + second;
@JoiWilliam: 哥们不行啊
@acfun的怨念:
if(second.length<2)
{
second = "0" + second;
}
// 注意赋值逻辑
cc.innerHTML = "<h2>"+day1+"天"+hour+"小时"+minute+"分"+second+"秒"+"</h2>";
@JoiWilliam: 还是不行
@acfun的怨念: if(second.length<2)
改成if(second<10)
@JoiWilliam: 多谢
写一个补充方法.所有的输出都调用这个方法.
方法就是输入一个字符串.再输入一个最小长度.当长度不够是在恰面加0补满.
PS.net的string里是自带的.js不知道
大神啊,我主要的确不太会啊,能给点提示不?