我想重新打开别人问的问题。用 live 或 delegate 模拟 mouseenter 的最佳方法是什么?原来的问题在这里:
我应该如何使用 jquery 的实时功能模拟 mouseenter 事件?
OP的提议是:
// mouseenter emulation
jQuery('.selector').live('mouseover',function (e) {
// live sees all mouseover events within the selector
// only concerned about events where the selector is the target
if (this != e.target) return;
// examine relatedTarget's parents to see if target is a parent.
// if target is a parent, we're "leaving" not entering
var entering = true;
jQuery(e.relatedTarget).parents().each(function () {
if (this == e.target) {
entering = false;
return false; // found; stop searching
}
});
if (!entering) return;
/*
the rest of my code
*/
});