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

How to use jquery function on

coldplay.xixi
Release: 2020-12-01 15:25:44
Original
2194 people have browsed it
<p>How to use jquery function on: The on method adds one or more event handlers on the selected element and child elements. The syntax is [$(selector).on(event,childSelector,data,function) 】.

<p>How to use jquery function on

<p>The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

<p>How to use jquery function on:

<p>Definition and usage

<p>on() method is used in selected elements and sub-elements Add one or more event handlers on the element.

<p>The on() method is the new replacement for the bind(), live() and delegate() methods. This method brings a lot of convenience to the API and is recommended because it simplifies the jQuery code base.

<p>Note: Event handlers added using the on() method apply to current and future elements (such as new elements created by scripts).

<p>Tip:

  • <p>To remove the event handler, use the off() method.

  • <p>To add an event that only runs once and then remove it, use the one() method.

<p>Syntax

$(selector).on(event,childSelector,data,function)
Copy after login
<p>How to use jquery function on

<p>Add a click event handler to the <p> element:

$(document).ready(function(){
  $("p").on("click",function(){
    alert("段落被点击了。");
  });
});
Copy after login

The above is the detailed content of How to use jquery function on. 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