繁体   English   中英

停用并激活电子邮件表单

[英]Deactivating and activating an E-mail form

我正在尝试获取下面的代码以保持电子邮件表单停用,直到页面完全加载后6秒。 我能做些什么让它像那样工作? 谢谢

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;
   }

使用setTimeout

window.setTimeout(function() {  
    // Do whatever you need
}, 6000); 

对持续时间进行硬编码并不是一个好主意。 相反,您应该使用异步调用来调用activate。

无论如何,这是工作代码。

<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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM