Get the App
SLTechnology News&Howtos  ›  Development  › 

How to bind jquery events

Shulou Source: shulou.com Published: 2022-06-01 06:06:52 10月02日 Update

In this article, the editor introduces in detail "how to bind jquery events". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to bind jquery events" can help you solve your doubts.

1. Bind ()

Bing () is used to bind events, for example:

2. Unbind ()

Unbind () is used to unbind the event. For example:

3. On ()

The on () method is used to bind events, such as:

4. Off ()

The off () method is used to unbind an event, for example:

Note:

It is recommended to bind events with the on () method, which is more efficient.

5. Example event binding $(function () {/ / normally the mouse moves into the background color to become gray Turns white when removed / / mouse moves in / * $("# menu li") .Mouseover (function () {$(this) .css ("background-color", "gray")) }); / / move the mouse out of $("# menu li") .mouseout (function () {$(this) .css ("background-color", "white");}) * / bind () bind event $("# menu li") .bind ("mouseover", function () {$(this) .css ("background-color", "gray");}) ("# menu li") .bind ("mouseout", function () {$(this) .css ("background-color", "white");}) / / bind () bind multiple events / * $("# menu li") .bind ("click mouseover", function () {$(this) .css ("background-color", "gray");}) * / bind () bind multiple events / * $("# menu li") .bind ({click:function () {$(this) .css ("background-color", "# ccc");}, mouseover:function () {$(this) .css ("background-color", "yellow");}}) * / / unbind event / / $("# menu li"). Unbind (); / / unbind all events / / $("# menu li") .unbind ("click") / / only release click event, leave mouse move event / / on () bind event / / handle adding background color effect $("# menu") .on ("mouseover", "li", {}, function () {$(this) .css ("background-color", "# ccc");}) $("# menu"). On ("mouseout", "li", {}, function () {$(this) .css ("background-color", "yellow");}); / / off () unbind $("# menu") .off ("mouseout", "li"); / / remove only moustout events}) HTML XHTML CSS has finished reading this article "how to bind jquery events". If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about related articles, you are welcome to follow the industry information channel.

Tags: Event mouse article method content multiple background processing proper suggestion idea situation effect efficiency new knowledge time-varying more step gray white Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker MySQL Xiaomi macOS