2个回答
展开全部
你好,给你写了个简单的例子,为了方便检验,例子使用10秒做间隔
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p id="q-box"></p>
<div class="next-step">
<input type="button" value="下一题(10秒后可点)" id="click-next" disabled>
</div>
<script>
(function(){
var qArr = ['1、这是第一个问题?', '2、这是第二个问题?', '3、这是第几个问题?'],
start = 0,
diff = 10;
var qb = document.getElementById("q-box"),
nb = document.getElementById("click-next");
function startInterval() {
var counter = 0,
_timer = null;
_timer = setInterval(function(){
counter++;
console.log(counter);
if (counter === diff) {
nb.value = "下一题";
nb.removeAttribute('disabled');
clearInterval(_timer);
_timer = null;
}
}, 1000);
}
qb.innerHTML = qArr[start++];
startInterval();
nb.onclick = function(ev){
if (qArr[start++]) {
qb.innerHTML = qArr[start];
nb.value = "下一题(10秒后可点)";
nb.setAttribute('disabled', 'disabled');
startInterval();
}
}
})();
</script>
</body>
</html>
希望是你想要的答案,如果有什么疑问,欢迎追问,望采纳~~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询