如果我有以下 JQuery:
$('#div1, #div2').scroll(function() { my_function($(this)); });
或
$('#div1, #div2').live('mouseover',function(){ my_function($(this)); });
$(this)
代表什么?
它是 DIV1 还是 DIV2 的 DOM 对象?还是那个 DIV 的 HTML?
上面代码中“this”代表什么?
最佳答案
this
是触发事件的 DOM 元素,在本例中为 #div1
或 #div2
。
$(this)
是对 jQuery 的调用以将 DOM 元素包装在 jQuery 的包装器中,因此您可以使用 jQuery 函数(例如 .text()
、.bind()
, .load()
) 就可以了。
关于javascript - JQuery:帮助解决 ".live"和 ".scroll",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4138476/