如果在它之前发生的 mousedown 事件延迟它,则模糊事件似乎会丢失

Rah*_*edi 5 javascript dom-events

这是代码:

<input type="text" onblur="myFunction()">
<div style="border: 1px solid; width:300px;height:300px" onmousedown = "myOtherFunction()">


function myOtherFunction(){
  console.log("mousedown on div occurred");
}

function myFunction(){
  console.log("blurr occurred");
}
Run Code Online (Sandbox Code Playgroud)

如果我在输入中输入一些内容并点击 div,这会按预期工作,mousedownblur. 但是,如果我只是放入调试器myOtherFunction并打开开发人员工具,则blur事件不会被触发并且似乎丢失了。是否可能是因为调试器打开时发生的“延迟”?

https://jsbin.com/qevapocovo/edit?html,js,console,output

Tas*_*sos 0

这实际上是 Chrome 上的调试器问题:如果您注意到我的录音,您会看到我单击了 Web 应用程序内出现的“播放”按钮,而在您的录音中,您单击了开发人员工具内的调试器的“播放”按钮标签。您能否单击访问断点时弹出的页内“播放”并验证其按预期工作?

编辑:我创建了一个 html 文件,使用相同的代码直接在 Chrome 上运行,但问题仍然存在:

function myOtherFunction(){
  debugger
  console.log("mousedown on div occurred")
  alert("mousedown on div occurred")
}

function myFunction(){
  console.log("blurr occurred")
  alert("blurr occurred")
}
Run Code Online (Sandbox Code Playgroud)
<input type="text" onblur="myFunction()">
<div style="border: 1px solid; width:300px;height:300px" onmousedown = "myOtherFunction()"></div>
Run Code Online (Sandbox Code Playgroud)

我也在 Safari 上尝试过并且工作正常。