Simply put, focus() does not support bubbling but focusin() supports bubbling
Example:
HTML
<p id="p1"> <input type="text"></p>
If it is focus(), Then it must be written as
$('input').on('focus',function(){ alert(123); });
written as
$('#p1').on('focus',function(){ alert(123);//无效 });
and focusin()
written as
$('#p1').on('focusin',function(){ alert(123);//有效 $('#p1').off('focusin'); });
Simply put, focus() is not supported Bubbling and focusin() supports bubbling
Example:
HTML
<p id="p1"> <input type="text"></p>
If it is focus(), it must be written as
$('input').on('focus',function(){ alert(123); });
Written as
$('#p1').on('focus',function(){ alert(123);//无效 });
And focusin()
is written as
$('#p1').on('focusin',function(){ alert(123);//有效 $('#p1').off('focusin'); });
The above is the detailed content of Detailed explanation of the difference between JQuery focus() and focusin(). For more information, please follow other related articles on the PHP Chinese website!