Home > Web Front-end > JS Tutorial > body text

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

黄舟
Release: 2017-06-27 13:15:01
Original
2338 people have browsed it

Simply put, focus() does not support bubbling but focusin() supports bubbling

Example:
HTML

<p id="p1">
    <input type="text"></p>
Copy after login
Copy after login

If it is focus(), Then it must be written as

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

written as

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

and focusin()
written as

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

Simply put, focus() is not supported Bubbling and focusin() supports bubbling

Example:
HTML

<p id="p1">
    <input type="text"></p>
Copy after login
Copy after login

If it is focus(), it must be written as

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

Written as

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

And focusin()
is written as

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template