1

这两个事件都在 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>
4

2 回答 2

4

终于解决了。谢谢大家的帮助!

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

    }
于 2012-06-12T15:28:06.227 回答
1
 window.onblur = function() { 
      $('#msg').html($('#msg').html() + '<br/> Blur');     
      return false;
 }; 

可能是事件正在冒泡。

于 2012-06-07T12:01:23.267 回答