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!