gpt4 book ai didi

javascript - 如何在 onclick JS 函数后返回之前的文本?

转载 作者:数据小太阳 更新时间:2023-10-29 04:34:42 26 4
gpt4 key购买 nike

我的代码是:

    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>

关于javascript - 如何在 onclick JS 函数后返回之前的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32459900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com