为了重现此问题,请使用[1]中的fiddle并按照以下步骤操作:
同样的JavaScript代码如下:
该问题在“Chrome”和“Firefox”中都能重现。这是“Chrome”中已知的错误还是其他人遇到过类似的问题?理想情况下,按钮上的单击事件应该被触发,但不知何故没有触发?我无法理解原因或可能的修复方法。我不想使用setTimeout()来推迟“blur”事件的执行。
[1] https://jsfiddle.net/cg1j70vb/1/
点击文本框
在文本框中输入一些值
在输入值后,点击“click me”按钮。请注意,不要在浏览器上其他地方单击。
您会发现“button click”事件未被触发。
<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>
同样的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("")
})
})
该问题在“Chrome”和“Firefox”中都能重现。这是“Chrome”中已知的错误还是其他人遇到过类似的问题?理想情况下,按钮上的单击事件应该被触发,但不知何故没有触发?我无法理解原因或可能的修复方法。我不想使用setTimeout()来推迟“blur”事件的执行。
[1] https://jsfiddle.net/cg1j70vb/1/
visibility:hidden
属性。这不会使按钮上移。 - Sandeep Nayak