2014-03-31 325 views
0

我想执行$(“绳”)。自动点击()函数页面完全加载后。触发onClick();在页面加载

<script type="text/javascript"> 
    $(document).ready(function() { 

     $curtainopen = false; 
     $(".rope").click(function(){ 
      $(this).blur(); 
      if ($curtainopen == false){ 
       $(this).stop().animate({top: '0px' }, {queue:false, duration:350, easing:'easeOutBounce'}); 
       $(".leftcurtain").stop().animate({width:'60px'}, 4500); 
       $(".rightcurtain").stop().animate({width:'60px'},4500); 
       $curtainopen = true; 
      }else{ 
       $(this).stop().animate({top: '-40px' }, {queue:false, duration:350, easing:'easeOutBounce'}); 
       $(".leftcurtain").stop().animate({width:'50%'}, 4500); 
       $(".rightcurtain").stop().animate({width:'51%'},4500); 
       $curtainopen = false; 
      } 
      return false; 
     }); 

    }); 
</script> 

请帮忙。

+1

相反评论每个答案的,我在这里告诉你:'.trigger(“点击”)'快'是。点击()'。 –

回答

2

使用.click().trigger('click')与选择:

$(".rope").click(); 
//or 
$(".rope").trigger('click'); 
1

您可以将侦听器定义后写:在DOM准备

$(".rope").click() 

$(".rope").trigger('click') 
0

我想IT连锁背后:

$(".rope").click(function(){ 
    $(this).blur(); 
    if ($curtainopen == false){ 
     $(this).stop().animate({top: '0px' }, {queue:false, duration:350, easing:'easeOutBounce'}); 
     $(".leftcurtain").stop().animate({width:'60px'}, 4500); 
     $(".rightcurtain").stop().animate({width:'60px'},4500); 
     $curtainopen = true; 
    }else{ 
     $(this).stop().animate({top: '-40px' }, {queue:false, duration:350, easing:'easeOutBounce'}); 
     $(".leftcurtain").stop().animate({width:'50%'}, 4500); 
     $(".rightcurtain").stop().animate({width:'51%'},4500); 
     $curtainopen = false; 
    } 
    return false; 
}).click();