例:
HTML代码:
JS代码:
function calcTime(){
var num = parseInt(document.getElementById("num").value);
var sdt = new Date();
for(var i = 0 ; i < num ; i++) {
userDirFunc(i + "");
}
var edt = new Date();
var seconds = "总共用时" + (edt.getTime() - sdt.getTime()) / 1000 + "s";
userDirFunc(seconds);
}
function userDirFunc(count) {
document.getElementById("show").innerText = count;
}
运行结果:
运行看看