【问题标题】:Deactivating and activating an E-mail form停用和激活电子邮件表单
【发布时间】:2011-11-21 06:18:27
【问题描述】:

我正在尝试获取下面的代码,以使电子邮件表单保持停用状态,直到页面完全加载后 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;
   }

【问题讨论】:

    标签: javascript forms javascript-events


    【解决方案1】:

    硬编码持续时间不是一个好主意。相反,您应该使用异步调用来调用激活。

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

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

    【讨论】:

    • Sandeep 如何通过异步调用调用激活?
    • 您可以将 disabled 默认设置为 true (HTML)。加载完成后,您可以将 disabled 设置为 false。如果您使用的是 jquery - 您可以执行 $(function() { //set disabled to false });或使用 jQuery blockUI 插件 (malsup.com/jquery/block),如果发生任何负载,它将阻止 UI。
    【解决方案2】:

    使用setTimeout

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

    【讨论】:

      【解决方案3】:

      你可以使用setTimeout函数:

      setTimeout("your function to be called to activate an email form", 6000);
      

      【讨论】:

        猜你喜欢
        • 2014-06-04
        • 1970-01-01
        • 1970-01-01
        • 2014-06-24
        • 2014-02-10
        • 2013-10-05
        • 1970-01-01
        • 1970-01-01
        • 2013-01-13
        相关资源
        最近更新 更多