2 回答

TA貢獻1864條經驗 獲得超2個贊
看起來您正在尋找一個 setInterval。試試這個代碼:
<!DOCTYPE html>
<html>
<body>
<p>Example</p>
<input id="myText" type="text" name="fname" value="delete this">
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var asd = setInterval(refresh, 1500);
function refresh()
{
var resetbutton = document.getElementById("myText");
resetbutton.value="";
resetbutton.focus();
}
}
</script>
</body>
</html>
我希望它有幫助!

TA貢獻1890條經驗 獲得超9個贊
您可以使用 setTimeout() 然后清除該值并重新關注文本區域。下面你可以看到一個關于鼠標移出事件的例子。
<script>
const resetbutton = document.getElementById("myText");
resetbutton.onmouseout = function() {
//1 second delay
let delay = 1500;
setTimeout(function() {
//clear value and re-focus
resetbutton.value="";
resetbutton.focus();
}, delay);
};
</script>
添加回答
舉報