数不上停

时间:2013-01-18 15:22:13

标签: javascript

需要的是,计数器应该在按钮点击后开始,当开始计数时 - 开始按钮必须处于非活动状态,完成计数后 - 按钮必须处于活动状态并且有某人功能。

var refDate = new Date("2013 01 18 16:41");
var prepend = "This is a message ";
var append = new Date(refDate).toLocaleString();
var refValue = "1,100.00";

function insertCommas(nAmt) {
var currAmt = nAmt.toFixed(2);
while (/(\d+)(\d{3})/.test(currAmt)) {
currAmt = currAmt.replace(/(\d+)(\d{3})/, "$1,$2");
}
return currAmt;
}

function dispCounter() {
var currDate = new Date();
var elapsedSeconds = Math.round((refDate - currDate) / 100);
var elapsedValue = elapsedSeconds / 100;
var nRef = refValue.replace(/\,/g, "");
var result = insertCommas(nRef - elapsedValue);
document.getElementById('upCount').innerHTML = prepend + " $" + result + " since " + append;
setTimeout("dispCounter()", 1500);
}

navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', dispCounter, false) : addEventListener('load', dispCounter, false);

0 个答案:

没有答案