简体   繁体   English

触发onClick(); 页面加载

[英]Trigger onClick(); on page load

I want to execute $(".rope").click() function automatically after page has loaded completely. 我想在页面完全加载后自动执行$(“。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>

Please Help. 请帮忙。

use .click() or .trigger('click') in dom ready with selector: 在准备好选择器的dom中使用.trigger('click') .click().trigger('click')

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

You can write this after your listener definition: 您可以在侦听器定义之后编写以下代码:

$(".rope").click()

or 要么

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

I'd like to chain it behind: 我想将其链接:

$(".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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM