JavaScript FocusOut - get the element that receives focus

后端 未结 4 777
青春惊慌失措
青春惊慌失措 2021-02-13 13:03

When the FocusOut event is raised, how do you know which element receives the focus?

The correct way seems to be to use the event\'s relatedTarget p

4条回答
  •  盖世英雄少女心
    2021-02-13 13:30

    //attach a focus out handler
    $("#id").focusOut($El_FocusOut);
    
    //display the id of new element being focused onto
    function $El_FocusOut($eventArgs){
        //firefox specific focusout active element logi
        var activeElement = $eventArgs.originalEvent.explicitOriginalTarget;
        alert($(activeElement).attr("id"))
    }
    

提交回复
热议问题