如何在 JavaScript 计时器到期后显示按钮?我正在使用 Visual Studio 2010 并基于 ASP 项目进行此操作。
我当前的计时器代码如下:
<script type="text/javascript">
function countDown(sec, elem) {
var element = document.getElementById(elem);
element.innerHTML = "Time left: " + sec + " seconds";
if (sec < 1) {
clearTimeout(timer); //clear timeout
element.innerHTML = 'Time is up!';
document.getElementById("<%=btnPresentAnswer.ClientID %>").Visible = true;
}
sec--;
var timer = setTimeout('countDown(' + sec + ', "' + elem + '")', 1000);
}
</script>
<div id="status"></div>
<script type="text/javascript">
countDown(5, "status");
</script>
最佳答案
也许您应该将 display:none 添加到按钮,然后如果计时器完成,那么您应该将显示值替换为 block 。
示例: 假设你这里有 html block 那么这就是按钮
// html
// head
// end head
// body
<button style="display:none">Test</button> // this will not show in the UI
<script>
// your timer function
// then if timer is up you should manipulate the display:none turn it into this display:block;
</script>
//end body
// end html
关于javascript - javascript 计时器到期后显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46461140/