87,910
社区成员
发帖
与我相关
我的任务
分享
<button type="button" onclick="fun()">弹出</button>
<script type="text/javascript">
var stare = "A";
function fun(){
if(stare == "A"){
stare = confirm("是否【选择】?") ? "B":"A";
}else{
stare = confirm("是否【取消】?") ? "A":"A";
}
}
</script>
<textarea name="a" id="a" cols="30" rows="10"></textarea>
<button type="button" onclick="timedCount('a',50000)">开始</button>
<button type="button" onclick="stopCount('a')">停止</button>
<button type="button" onclick="clearAll('a')">清空</button>
<script type="text/javascript">
var t;//不需要它
function timedCount(id, c) {///////id为你容器id,c为要倒计时的数字
var temptextmin = document.getElementById(id);
//c = 0; 如果初始化了又何必传c进来?
var hour = parseInt(c / 3600);
var min = parseInt(c / 60) % 60;
// if (min >= 60) {
// min = min % 60
// }
var lastsecs = c % 60;
temptextmin.value = hour + "时" + min + "分" + lastsecs + "秒";
c = c + 1;
window['timer' + id] = setTimeout(function () { timedCount(id,c) }, 1000);///////全局遍历存储计时器句柄
}
function stopCount(id) {//
clearTimeout(window['timer' + id]);///
}
function clearAll(id) {
document.getElementById(id).value = "0时" + "0分" + "0秒";
clearTimeout(window['timer' + id]);///
}
</script>