【发布时间】:2018-05-01 17:51:47
【问题描述】:
我有以下物品:
<a class="btn btn-danger w-100" style='color: White' id='refresh_button' onclick="activateAutorefresh()"> ↺ </a>
我想要以下内容:如果类是 btn-danger,onClick 将其更改为 btn-success 并以 5000 毫秒的超时激活自动刷新。如果再次单击按钮,请将类更改为 btn-danger 并禁用自动刷新。
所以,我有以下代码:
function activateAutorefresh(){
if (document.getElementById("refresh_button").classList.contains('btn-danger')){
document.getElementById("refresh_button").classList.remove('btn-danger');
document.getElementById("refresh_button").classList.add('btn-success');
}
else {
document.getElementById("refresh_button").classList.remove('btn-success');
document.getElementById("refresh_button").classList.add('btn-danger');
}
}
我不知道如何激活/禁用页面自动刷新。我该怎么做?
此外,在刷新时保持当前的自动刷新状态。
【问题讨论】:
标签: javascript html refresh