要重现此问题,请使用[1]中的小提琴并按照以下步骤操作:
单击文本框
输入一些值
输入值后,单击"单击我"按钮.请注意,请勿单击浏览器上的任何其他位置
你会看到"按钮点击"事件没有被触发.
HTML代码如下所示,
<div class="wrapper">
<input type="text" id="input"/>
<div class="error">There is an error </div>
</div>
<button type="button" id="button">Click Me</button>
<div id="log">Logs</div>
Run Code Online (Sandbox Code Playgroud)
相同的JavaScript代码是:
$(function () {
$("input,button").on("click focus blur mousedown mouseup", function (e) {
$("#log").append($("<div/>").html(e.target.id + " " + e.type))
var self = this
if (self.id === "input" && e.type=="blur") {
$(self).trigger("exit")
}
})
$(".wrapper").on("exit", function () {
$(this).find(".error").hide()
$(this).find(".error").text("")
})
})
Run Code Online (Sandbox Code Playgroud)
该问题可在"Chrome"和"firefox"中重现.这是"Chrome"或任何遇到任何类似问题的人都知道的错误吗?
理想情况下,按钮上的click事件必须被触发,但不知何故它没有?我无法理解原因或可能的解决方法.
我不想使用setTimeout()来推迟"模糊"事件执行