更新时间:2022-10-15 09:10:50
你说的是这样?
html
<div id="show" style="display:none;">哦</div>
<button id="btn">点我啊</button>
js
var timeoutHandler = null;
document.getElementById('btn').onclick = function(){
var show = document.getElementById('show');
if(timeoutHandler){
clearTimeout(timeoutHandler);
}
show.style.display = 'block';
timeoutHandler = setTimeout(function(){
show.style.display = 'none';
},5000);
};