【发布时间】:2017-08-02 10:17:05
【问题描述】:
<html>
<head><title>asdf</title></head>
<body>
<input type="text" id="WTF">
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
$("#WTF").blur(function () {
if($("#WTF").val() !== "WTF"){
alert("WTF!");
$("#WTF").focus();
}
});
</script>
</body>
</html>
喜欢这段代码。 如果在 IE 中打开,可以在下次激活模糊事件之前正确触发一次警报。但是在Chrome中打开,可以看到alert无限触发。 为什么?以及如何让Chrome正确激活事件?
【问题讨论】:
-
因此,在 chrome 中,
alert之后的焦点仍然在input上,因此您的blur会被反复触发。你有什么要求?你想在input上做什么? -
Emmm,我想在输入失去焦点时验证输入值。如果不通过,通过alert提示输入错误。最后将注意力集中在输入上。 ——就像这段代码。
-
我想知道为什么 IE 和 Chrome 处理方式不同
标签: jquery google-chrome internet-explorer