Я пытаюсь предотвратить событие щелчка при стрельбе, и я сделал почти все, о чем я могу думать. Что происходит, вы нажимаете кнопку отправки, которая затем выполняет некоторую проверку, и если это не удается, я представляю всплывающую подсказку по этой причине. Чтобы показать наконечник инструмента, введите $element.append($tooltip)
, который затем вызывает $(body).on('click', function() {})
append() триггеры on ('click')
Я проверил, что если я удалю добавление, щелчок не будет запущен.
Кто-нибудь знает, почему добавить его, вызвав событие click?
Подробнее Код. Это фактический код ToolTip:
//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;
};
Пожалуйста, разместите еще один код. – Blazemonger
Единственный способ, которым это может случиться, это то, что $ tooltip имеет javascript внутри него, который запускает событие click. –
@KevinB Я посмотрел повсюду на любую возможность нового элемента, содержащего триггер, но не существует. Я буквально просто добавляю div в другой div. – tuck