书中讲到jQuery自定义事件时举了这样一个例子,使用自定义事件来移除container中的tooltip,而别的container中的tooltip不受影响:
请问代码中的$tooltip是什么?为什么这样做就会 each tooltip will listen to its container?跟事件冒泡有关吗?
中文版在此: http://www.itxueyuan.org/view/6933.html
谢谢。
But implementing this behavior with event logic rather than selector logic is easy.
// $container could be $('#sidebar') or $(document)
$container.triggerHandler('newTooltip');
$container.one('newTooltip', function() {
$tooltip.remove();
});
(Notice the use of jQuery’s one instead of on. The difference is that one automatically removes the handler after it fires.)
With these two lines of code, each tooltip will listen to its container and remove itself when the container gets a new tooltip.
请问代码中的$tooltip是什么?为什么这样做就会 each tooltip will listen to its container?跟事件冒泡有关吗?
中文版在此: http://www.itxueyuan.org/view/6933.html
谢谢。
But implementing this behavior with event logic rather than selector logic is easy.
// $container could be $('#sidebar') or $(document)
$container.triggerHandler('newTooltip');
$container.one('newTooltip', function() {
$tooltip.remove();
});
(Notice the use of jQuery’s one instead of on. The difference is that one automatically removes the handler after it fires.)
With these two lines of code, each tooltip will listen to its container and remove itself when the container gets a new tooltip.