为什么alert()会破坏代码执行? [英] why does alert() break code execution?

查看:285
本文介绍了为什么alert()会破坏代码执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们使用 alert()时,有时代码会中断。

When we use alert(), some times the code breaks.

例如:

HTML:

<span>Hi</span>

Javascript:

Javascript:

$(document).ready(function () {

    $("span").dblclick(function () {
        alert("b");
    });
    $("span").click(function () {
        alert("a");
    });

});

警报(b)不甚至不会出现。

但如果我们将 alert()更改为 console.log ,它被记录。

But if we change both the alert() to console.log, it is logged.

警示演示& console.log演示

那么,什么是发生了什么?

So, what's happening?

推荐答案

alert 打开模型对话框。当它打开时,你不能与页面的任何部分进行交互,除了警报本身。

alert opens a model dialogue. When it is open, you can't interact with any part of the page except the alert itself.

由于你无法与页面交互,下半部分双击不能达到跨度,因此双击事件不会触发。

Since you can't interact with the page, the second half of the double click can't reach the span, so the double click event won't fire.

这篇关于为什么alert()会破坏代码执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆