我的代码是:
function changeText()
{
document.getElementById('button').innerHTML = 'Downloading...';
}
按钮:
<button id = "button" onclick='changeText()' value='Change Text'>Download file as CSV</button>
我希望按钮更改为“正在下载…”,然后在几秒钟后返回“以CSV格式下载”,这可能在JS中吗?
解决方法
您可以使用setTimeout或异步调用成功:
function changeText() {
document.getElementById('button').innerHTML = 'Downloading...';
setTimeout(prevIoUsText,1000);
}
function prevIoUsText() {
document.getElementById('button').innerHTML = 'Download file as CSV';
}
<button id="button" onclick='changeText()' value='Change Text'>Download file as CSV</button>