使用IE8时[removed]事件也触发[removed]事件([removed] event al

2019-09-17 20:12发布

这两个事件在时间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>

Answer 1:

最后它得到了解决。 谢谢所有帮助!

$(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');
        }

    }


Answer 2:

 window.onblur = function() { 
      $('#msg').html($('#msg').html() + '<br/> Blur');     
      return false;
 }; 

可能是该事件得到冒泡。



文章来源: window.onblur event also triggers window.onfocus event when using IE8