2 回答

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊
看起來您正在尋找一個(gè) setInterval。試試這個(gè)代碼:
<!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貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
您可以使用 setTimeout() 然后清除該值并重新關(guān)注文本區(qū)域。下面你可以看到一個(gè)關(guān)于鼠標(biāo)移出事件的例子。
<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>
添加回答
舉報(bào)