I'm trying to get the code below to keep an E-mail form deactivated until 6 seconds after the page is fully loaded. What can I do to make it work like that? Thanks
var inActive = true;
function inActive() {
if (!inActive)
return true;
inActive = true;
document.getElementById("myForm").disabled = true;
setTimeout(function() {
inActive = true;
document.getElementById("myForm").disabled = false;
}, 1000);
return true;
}
Use setTimeout .
window.setTimeout(function() {
// Do whatever you need
}, 6000);
It is not a good idea to hard code the duration. Instead you should call the activate using asynchronous call.
Anyways, here is the working code.
<script type="text/javascript">
window.onload = function(){
var inActive = true;
function inActivate() {
if (!inActive)
return true;
inActive = true;
document.getElementById("myForm").disabled = true;
setTimeout(function () {
inActive = true;
document.getElementById("myForm").disabled = false;
}, 4000);
return true;
}
inActivate();
};
</script>
您可以使用setTimeout
函数:
setTimeout("your function to be called to activate an email form", 6000);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.