【发布时间】:2011-04-07 16:34:45
【问题描述】:
使用 $(this) 与 this 的根本区别是什么
$('.viewComments').click(function(ev){
//returns the desired value
alert(this.getAttribute('id'));
//Gives an error sayin function is not defined
alert($(this).getAttribute('id'));
//returns the desired value
alert($(this).attr('id'));
});
我认为“$(this)”将包含“this”具有的所有功能以及更多功能。但似乎并非如此。
那么 $(this) 到底是什么?和
我在使用时如何知道有哪些功能可用? (我知道我可以通过 firebug 获取它们。但我想知道是否有其他方法 - 可能是某些文档)
【问题讨论】: