我遇到了一个初学者问题。我有“菜单”,菜单是样式表,并在 jQuery 中获得了使菜单移动的代码。我的问题是,为什么我不能在代码中使用 $this 变量?我是 jQuery 的新手,所以请耐心等待。我很高兴得到任何答复。
$(document).ready(function(){
$('.item').hover(function(){
$($this).stop().animate({paddingLeft: '20px'}, "slow");
}, function(){
$($this).stop().animate({paddingLeft: '0px'}, "slow");
});
});
我的代码:jsFiddle
最佳答案
它应该是$(this)
关于javascript - 无法在 jQuery 中使用 $this,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16125076/