A Brief Introduction to the usage of bind in jQuery, jquerybind

Source: Internet
Author: User

A Brief Introduction to the usage of bind in jQuery, jquerybind

Bind Introduction

The bind () method adds one or more event handlers to the selected element and specifies the function that runs when an event occurs.

Syntax

$(selector).bind(event,data,function)

Event is required. One or more events added to an element, such as click, mouseover, mouseup, change, and select

Data is optional. Extra data passed to the function, such as $ (selector). bind ("click", "input", function (){});

Function () {} is required. Function triggered by event binding

Bind multiple functions

$ ("Button "). bind ({// note that the format is json click: function () {$ ("div" ).css ("border", "5px solid orange");}, mouseover: function () {$ ("div" ).css ("background-color", "red") ;}, mouseout: function () {$ ("div" ).css ("background-color", "# FFFFFF ");}});

4. bind data

// Bind () bind the click Event parameter 2 and print the parameter 2 $ ('click '). bind ('click', ['luaf', 'solon', 'usop'], function (event) {alert (event. data [0]); // Lu Fei });

5. unbind bind event Removal

Html code

<Button> unbind () </button> <p> click here to delete the event of the preceding button </p>

Js Code

// Bind () bind multiple click events $ ('click '). click (function () {alert ('I am the first click') ;}); $ ('button '). click (function () {alert ('I am the second click') ;}); $ ('button '). bind ('click', function () {alert ('I am the third click') ;}); // unbind () delete click Event $ ('P '). bind ('click', function () {$ ('click '). unbind ('click'); alert ('button click Event delete ');});

The above is a brief introduction to the usage of bind in jQuery, which I will introduce to you. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.