Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
.foo在用户处理数据的过程中,我的表将有许多 TD 元素,它们被分配一个类。该表可能有几百个单元格,其中只有十几个可以获取.foo该类。我想听听hover那些特定的 TD 元素。看起来 jQuery 中的 delegate() 方法似乎在监听javascript事件,而hover实际上是jQuery事件,对吗?如何创建一个委托来监听将来将分配给他们的类hover的TD.foo元素?.foo
.foo
hover
TD.foo
不建议在较新的 jQuery 中使用委托,您应该使用
从 jQuery 1.7 开始,.delegate() 已被 .on() 方法取代。
$('#table').on('mouseenter mouseleave', 'td.foo', function(e) { if(e.type === 'mouseenter') { //hover in } else { //hover out } });
$("#tblId").on("hover", ".foo", function() { // Code here });