this与$(this)

  在事件处理中,想用this来代表事件的对象,却不能成功。原来,this是html的元素,是javascript的对象,要用jquery访问,需要用$(this)。如下面可以显示链接的位置。

$(document).ready(function(){
    $("#aa").mouseover(function(){
      alert($(this).position().left);
    })
});

  而用this则是常规的dom对象

$(document).ready(function(){
    $("#aa").mouseover(function(){
      alert(this.href);
    })
});

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-02-17
  • 2021-12-13
猜你喜欢
  • 2021-11-30
  • 2021-12-26
  • 2021-07-08
  • 2021-11-17
  • 2022-12-23
相关资源
相似解决方案