要重现此问题,请使用[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()来推迟"模糊"事件执行
我做了很多谷歌搜索:
以下是我发现的:
现在让我简要介绍每个C++转换操作符的原因和时间
的static_cast:
为何使用它而不是C型铸造?
static_cast用于执行相关类型之间的转换.
例子 :
Class A {};
Class B {};
A* a = new A();
B* b = static_cast<B*>(a); // Compiler error
B* b1 = (A*)a; // Works fine
float f;
int addr = (int)(&f); // Works fine
int addr = static_cast<int>(&f); // Compiler error
Run Code Online (Sandbox Code Playgroud)
但我想知道何时使用上述代码的真实用例?
reinterpret_cast:
reinterpret_cast 转换指向不相关类型的指针.
例子:
Class A {};
Class B {};
A* a = new A();
B* b = reinterpret_cast<B*>(a); // Works fine
B* …Run Code Online (Sandbox Code Playgroud)