读书人

jquery this跟$(this)

发布时间: 2012-11-12 12:31:58 作者: rapoo

jquery this和$(this)

起初以为this和$(this)就是一模子刻出来。但是我在阅读时,和coding时发现,总不是一回事。

What is "this"?

In many object-oriented programming languages, this (or self) is a keyword which can be used in instance methods to refer to the object on which the currently executing method has been invoked.

?

正确的代码:$("#textbox").hover(      function() {         $(this).attr(’title’, ‘Test’);      },      function() {         $(this).attr(’title’, ‘OK’);      });
?使用JQuery的好处是它包了各种浏览器版本对DOM对象的操作,因此统一使用$(this)而不再用this应该是比较不错的选择。

原文链接 http://www.cnblogs.com/RuiLei/archive/2009/08/20/1550804.html

读书人网 >Web前端

热点推荐