触发onClick();在页面加载

时间:2014-03-31 13:23:45

标签: javascript jquery

我想在页面完全加载后自动执行$(“。rope”)。click()函数。

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

请帮助。

3 个答案:

答案 0 :(得分:2)

在dom ready with selector中使用.click().trigger('click')

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

答案 1 :(得分:1)

您可以在听众定义后写下:

$(".rope").click()

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

答案 2 :(得分:0)

我想把它链接起来:

$(".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();
相关问题