我想知道如何在我的HTML/PHP iPad WebApp中使用JavaScript(或任何最好的)每隔'x'秒清除一个文本框。
感谢您的帮助!
香草javascript:每3秒清除一次输入值
setInterval(
function() {
document.getElementById("my-input").value = "";
}, 3000);
<input id="my-input" type="text" />
使用jQuery,您可以执行以下操作;
在2000的情况下,这是执行函数clear的毫秒数(即2秒),然后它会找到你想要清除的div并清空它。如果它是一个文本框值或你想清除的东西,只需更新函数以执行你需要的操作。
function clear() {
$("#yourIdToEmpty").clear();
}
setTimeout(clear, 2000);
使用jQuery,
$(document).ready(function(){
var interval = 1000; /*seconds * 1000. I'm using 1000 */
setInterval(function(){
$("#input").val('');
}, interval);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text' id='input'/>