これらの他のすべてのリスナーを追加する代わりに、実際に調べて、最も効果的な方法は、ウィジェットを継承して追加のフラグを追加することであると判断しました
http://code.jquery.com/ui/1.10.3/jquery-ui.js
ここにデモがあります
http://jsfiddle.net/3dX6d/7/
(function ($) {
$.widget("custom.tooltipX", $.ui.tooltip, {
options: {
focusPreventClose: false
},
close: function (event, target, content) {
if (this.options.focusPreventClose && $(this.element).is(":focus")) {
// Don't call the parent's close() call but therefore have to add event on focus out
this._on({ focusout:this.close });
} else {
this._superApply(arguments);
}
}
});
}(jQuery));
$('input').tooltipX({
focusPreventClose: true
});
他のソリューションと比較して、これは追加のオープン呼び出し (実際にはその中で他のいくつかの呼び出しを行う) でより多くの作業を行う必要はありません。元の投稿で要求されたように、要素にフォーカスがあるときにツールチップが閉じないようにするだけです。