为了账号安全,请及时绑定邮箱和手机立即绑定

不能用this?

$(document).ready(function(){
      
      this.click(function(){
          $(".car").animate({
              top:500
          },{
              duration:600
          })
      })
      
      
});

为什么不能用this而非得用$(".car")进行操作呢?

正在回答

2 回答

你这里的this指的是document根节点。

如果你想要的效果是点击该文档页面中任意位置都能触发该动画事件的话,

应该是用   this.onclick=function(){    //事件        }      -  this  JS对象

或者  this.click(function ...     改成  $(this).click(function ...      - $(this)  JQ对象

0 回复 有任何疑惑可以回复我~

知道啦

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

不能用this?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号