2011-11-21 90 views
0

我试图让下面的代码保持电子邮件表单停用,直到页面完全加载后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; 
    } 

回答

1

这不是一个好主意,硬编码的持续时间。相反,您应该使用异步调用来调用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> 
+0

Sandeep如何使用异步调用来调用activate? –

+0

默认情况下,您可以将残疾人设置为true(HTML)。一旦加载完成,您可以将禁用设置为false。如果你正在使用jquery - 你可以做$(function(){// set disabled to false});或者使用jQuery blockUI插件(http://malsup.com/jquery/block/),这会在发生任何负载时阻塞UI。 –

+0

太棒了!完美的作品。我感谢您的帮助。 –

1

使用setTimeout

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

可以使用setTimeout功能:

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