How to get div onblur event to execute a javascript function?

后端 未结 5 876
说谎
说谎 2020-12-14 03:29

Hi I have a div that contains three textboxes , i need a function to be called once the control is out of the div tag, I don\'t want to use the onclick event because the foc

5条回答
  •  长情又很酷
    2020-12-14 03:56

    You can bind the onblur event handler to each of the input elements and check in the handler if any of them have focus (using document.activeElement).

    
    
    

    Or, instead, using jQuery could simplify the process (especially if you have a lot of inputs):

    
    
    
    

    EDIT: I wrapped the event handlers inside a setTimeout to make sure that the other element had time to focus.

提交回复
热议问题