您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

jQuery:“ $(this)”到底是什么意思?

jQuery:“ $(this)”到底是什么意思?

this 是对调用当前函数的成员的引用…

那么您可以将其包装在jquery函数$()以选择它,就像选择其他选择器一样。

因此setInterval调用匿名函数,这样它就不会被可引用成员调用,因此它认为该window对象。

this上下文保存在变量中,然后像这样在内部使用它…

$(document).ready(function(){
    $("#round").click(function(){
        var clicked = this;   //<----store the click context outside setInterval
        setInterval(function(){
            $(clicked).animate(  //<----------use it here
                {height: 250,
                width: 150,
                top:150,
                left: 425},
                {duration: 300}
                ).
            animate(
                {height: 200,
                width: 200,
                top:200,
                left: 400},
                {duration: 300}
            );
        }, 0);
    });
});
JS 2022/1/1 18:14:24 有698人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶