小编Ris*_*hta的帖子

由于"模糊","点击"事件未被触发

要重现此问题,请使用[1]中的小提琴并按照以下步骤操作:

  1. 单击文本框

  2. 输入一些值

  3. 输入值后,单击"单击我"按钮.请注意,请勿单击浏览器上的任何其他位置

  4. 你会看到"按钮点击"事件没有被触发.

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()来推迟"模糊"事件执行

[1] https://jsfiddle.net/cg1j70vb/1/

html javascript jquery

8
推荐指数
1
解决办法
419
查看次数

C++ Casting Operators和传统的C cast操作符

可能重复:
什么时候应该使用static_cast,dynamic_cast和reinterpret_cast?

我做了很多谷歌搜索:

  1. 为什么要使用C++强制转换运算符而不是传统的C风格转换运算
  2. 何时使用C++强制转换运算符,一些实例?

以下是我发现的:

  • 传统上,任何C++转换运算符都用于更好地维护代码(即)我们可以通过搜索这种复杂符号(reinterpret_cast <)而不像C样式转换运算符,轻松找到代码中使用转换的位置.

现在让我简要介绍每个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)

c++ casting

6
推荐指数
1
解决办法
2019
查看次数

标签 统计

c++ ×1

casting ×1

html ×1

javascript ×1

jquery ×1