萌新求助
javascript吧
全部回复
仅看楼主
level 1
Zeja 楼主
各位大佬,有谁能帮忙看一下这个代码有什么问题,谢谢!
(出现问题:按下按钮前正常,按下后靠左显示"开始!",而且网站标题改为“test.html”,网页再无变化)
<!DOCTYPE html>
<head>
<title>Test</title>
<style>
#pomotimerConsole{
text-align:center;
}
</style>
<script>
function sleep(d){
for(var t = Date.now();Date.now() - t <= d;);
}
function pomotimer(t){
document.write('<h2 id="pomotimerConsole">开始!</h2>');
if(t<0){
document.write('<h2 id="pomotimerConsole">结束!按刷新键重启程序。</h2>');
sleep(1000);
return 0;
}
else if(t>=0){
for(t==t;t<=0;t--){
if(t>=60&&t%60>=10){
document.getElementById("pomotimerConsole").innerHTML='<h2 class="text-center">Math.round(t/60)+" : "+t%60</h2>';
sleep(1000);
}
else if(t>=60&&t%60<10){
document.getElementById("pomotimerConsole").innerHTML='<h2 class="text-center">Math.round(t/60)+" : 0"+t%60</h2>';
sleep(1000);
}
else if(t<60&&t%60>=10){
document.getElementById("pomotimerConsole").innerHTML='<h2 class="text-center">"0"+Math.round(t/60)+" : "+t%60</h2>';
sleep(1000);
}
else if(t<60&&t%60<10){
document.getElementById("pomotimerConsole").innerHTML='<h2 class="text-center">"0"+Math.round(t/60)+" : 0"+t%60</h2>';
sleep(1000);
}
else{
document.getElementById("pomotimerConsole").innerHTML='<h2 class="text-center">你的输入出现问题。请按刷新键重启程序。</h2>';
}
}
}
}
</script>
</head>
<body>
<button type="button" onclick="pomotimer(10)">程序开始</button>
</body>
</html>
2020年05月19日 01点05分 1
level 1
Zeja 楼主
按下按钮前
2020年05月19日 01点05分 2
level 1
Zeja 楼主
按下按钮后
2020年05月19日 01点05分 3
level 1
Zeja 楼主
dd
2020年05月19日 02点05分 4
level 1

2020年05月21日 05点05分 5
level 3
看懂了,是想写个计时器,可是我对dom没什么理解。你可以打几个断点看看怎么回事
2020年05月21日 05点05分 6
1