オンクリックイベントが発生しないようにしようとしていますが、考えられることはほぼすべて実行しました。何が起こっているのかというと、送信ボタンをクリックして少し検証を行い、失敗した場合はその理由でツールチップを提示します。入力したツールチップを表示するために入力する$element.append($tooltip)
と、トリガーされます$(body).on('click', function() {})
追加を削除してもクリックがトリガーされないことを確認しました。
なぜそれを追加してクリックイベントをトリガーするのか誰かが知っていますか?
ここにもっとコードがあります。これは実際のツールチップコードです。
//Sets up a tooltip to display feedback
//position: top, bottom or right
NG.Tooltip = function (target, message, timeout, position, doAdjust) {
var tt = (this == NG ? {} : this); //Prevent people from accidentally missing the "new" keyword and corrupting the global NG object
var $target = $(target);
var $targetParent = $target.parent();
var $offsetParent = $target.offsetParent();
tt.targetElement = $target.get(0);
if(!tt.targetElement){
return;
}
//Remove previous tooltip if there is one already attached to target element
if (tt.targetElement.ngTooltip)
tt.targetElement.ngTooltip.Remove();
if (!timeout) timeout = 2000;
var $div = tt.div = $('<div class="ngTooltip">' + message + '</div>');
var pos = $target.position();
var posParent = $targetParent.position();
if (position == 'bottom') {
$div.css({ "left": (pos.left) + "px", "top": (pos.top + $target.outerHeight() + 10) + "px" });
}
else if (position == 'top') {
$div.css({ "left": (pos.left) + "px", "top": (pos.top) + "px" });
}
else if (position == 'parent-bottom-left') {
$div.css({ "left": (posParent.left) + "px", "top": (pos.top + $target.outerHeight() + 10) + "px" });
}
else {
$div.css({ "left": (pos.left + $target.outerWidth() + 10) + "px", "top": pos.top + "px" });
}
// commenting out this allows the code to go without triggering the click
//$offsetParent.append($div);
if (position == 'parent-bottom-left') {
if ((posParent.left + $div.width()) > $offsetParent.width()) {
$div.css("width", ($offsetParent.width() - (posParent.left + 15)) + "px");
}
}
//Default to adjust it onscreen.
//But there are certain cases such as popping up the url of a (link) on hover where adjusting it would not work out well
if (doAdjust == null || doAdjust == true) {
NG.AdjustPopupOnScreen($div);
}
tt.Remove = function (elem) {
if (tt.timeoutId)
window.clearTimeout(tt.timeoutId);
$div.unbind('click'); //removes click event attached
$div.remove();
tt.targetElement.ngTooltip = null;
};
$div.click(tt.Remove);
tt.timeoutId = null;
if (timeout > 0)
tt.timeoutId = window.setTimeout(function () { tt.Remove(); }, timeout);
tt.targetElement.ngTooltip = this;
return this;
};