2014-03-31 309 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();