Home  >  Article  >  Web Front-end  >  Detailed explanation of the difference between JQuery focus() and focusin()

Detailed explanation of the difference between JQuery focus() and focusin()

黄舟
黄舟Original
2017-06-27 13:15:012326browse

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

    $(&#39;input&#39;).on(&#39;focus&#39;,function(){
        alert(123);
    });

written as

    $(&#39;#p1&#39;).on(&#39;focus&#39;,function(){
        alert(123);//无效
    });

and focusin()
written as

    $(&#39;#p1&#39;).on(&#39;focusin&#39;,function(){
        alert(123);//有效
        $(&#39;#p1&#39;).off(&#39;focusin&#39;);
    });

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

    $(&#39;input&#39;).on(&#39;focus&#39;,function(){
        alert(123);
    });

Written as

    $(&#39;#p1&#39;).on(&#39;focus&#39;,function(){
        alert(123);//无效
    });

And focusin()
is written as

    $(&#39;#p1&#39;).on(&#39;focusin&#39;,function(){
        alert(123);//有效
        $(&#39;#p1&#39;).off(&#39;focusin&#39;);
    });

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn