![](/img/trans.png)
[英]How to add a JavaScript alert message to show that the html form validation is correct using JavaScript
[英]How to show an alert message when no form field is used in 30 minutes using javascript/jquery?
我有一个带有几个输入字段的表单,我想要一个显示弹出消息的脚本,如果在某个时间范围后没有使用任何字段,则询问“你还在吗?” 或类似的东西。
可能吗? 请指教,谢谢!
您需要启动计时器30分钟,并将change
事件附加到您的所有字段。 在更改时,您要删除当前计时器,并再创建一个新计时器30分钟。
例如,它会是这样的:
$('input[type=text]').bind('change', function (e) {
// .. Triggered every time a form text field is changed
// .. Do stuff here
});
对于计时器,你只需使用settimeout
以下是JsFiddle中的完整示例:
我建议使用setTimeOut来调用要显示消息的方法或执行您想要执行的操作。 然后在所有输入类型的更改事件上尝试重置TimeOut。 这是模拟这种情况的JS代码:
// Timer for 3 seconds to call formTimeOut function
var _timer = setTimeout("formTimeOut()",3000);
$(function(){
// Monitor Value change of Inputs in your HTML
$("input").change(function(){
// Clear previous timer
clearTimeout(_timer);
// Reset the timer to re-run after 3 seconds.
_timer = setTimeout("formTimeOut()",3000);
});
});
// This is the function that will run after time out
function formTimeOut(){
// Timeout Logic goes here
alert("Are you there?");
}
您可以将$(“输入”)更改为适合您项目的任何条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.