【发布时间】:2014-02-24 05:59:17
【问题描述】:
我有一个这样的咖啡代码。
$('.foo').hover \
(-> $(this).css "cursor", "pointer"), \
(-> $(this).css "cursor", "default")
我想将此函数应用于动态附加的 DOM,所以我尝试像这样使用on() 来委托函数。
举个例子,我提到了this question
$(document).on 'hover', '.foo', (event) ->
$(this).css "cursor", "pointer" if event.type is "mouseover"
$(this).css "cursor", "default" if event.type is "mouseout"
但是这段代码根本不起作用。
如何将函数应用于动态添加的元素?
【问题讨论】:
-
The
.hover()method binds handlers for bothmouseenterandmouseleaveevents 而不是mouseover和mouseout。另外,请注意.on()对'hover'的支持是deprecated in jQuery 1.8, removed in 1.9。
标签: javascript jquery css coffeescript