gpt4 book ai didi

javascript - window.onblur 事件在使用 IE8 时也会触发 window.onfocus 事件

转载 作者:行者123 更新时间:2023-11-30 08:59:01 24 4
gpt4 key购买 nike

这两个事件都在 onblur 事件时被触发。

<%@ Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true"  CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication1.WebForm1" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="js/jquery-1.7.2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
window.onfocus = function() {
$('#msg').html($('#msg').html() + '<br/> focus');
};
window.onblur = function() {
$('#msg').html($('#msg').html() + '<br/> Blur');
};
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="msg">
</div>
</asp:Content>

最佳答案

终于解决了。感谢您的所有帮助!

$(window).bind("load", function() {
pageLoad();
});

var activeElement;

function pageLoad() {
activeElement = document.activeElement;
document.onfocusout = logWindow;
}

function logWindow() {
if (activeElement != document.activeElement) {
activeElement = document.activeElement;
}
else {
$('#msg').html($('#msg').html()+'<br/> Focus');
}

}

关于javascript - window.onblur 事件在使用 IE8 时也会触发 window.onfocus 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10929432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com