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

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

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);    });});


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5566505.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-14
下一篇2022-12-14

发表评论

登录后才能评论

评论列表(0条)

    保存