This example describes the use of the bind () method in jquery. Share to everyone for your reference. The specific analysis is as follows:
This method binds the event-handling method for a specific event that matches an element.
The bind () method and the one () method are the same in syntax, and they differ in the number of times the processing method of the binding is executed.
Grammatical structure One:
Copy Code code as follows:
$ (selector). bind (Type,data,function)
parameter list:
Parameters |
Describe |
Type |
Defines the type of event that is bound to a matching element. If more than one event is separated with a space. |
Data |
Optional. An additional data object that is passed to the event object. |
function |
Defines a method that runs when an event occurs. |
Instance code:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>bind () function-cloud-dwelling community </title>
<style type= "Text/css" >
div{
width:100px;
height:100px;
BORDER:1PX solid blue;
}
</style>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("div"). Bind ("click", Function () {$ ("div"). css ({color: "green", FontSize: "20px"})});
})
</script>
<body>
<div> Cloud-dwelling communities welcome you </div>
</body>
Grammatical structure two:
Copy Code code as follows:
$ (selector). Bind ({type:function, type:function, ...})
Parameter list:
Parameters |
Describe |
{type:function, type:function, ...} |
Defines the event and event handling methods that are bound to matching elements. The type and function parameters are described as the table above. |
Instance code:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>bind () function-cloud-dwelling community </title>
<style type= "Text/css" >
div{
width:100px;
height:100px;
BORDER:1PX Solid Red
}
</style>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("div"). Bind ({click:function () {$ ("div"). CSS ("Color", "green")},
Mouseover:function () {$ ("div"). CSS ("Background-color", "Blue")},
Dblclick:function () {$ ("div"). CSS ("Background-color", "Red")}
})
})
</script>
<body>
<div> Cloud-dwelling communities welcome you </div>
</body>
I hope this article will help you with your jquery programming.
This article is from: Ant Tribe http://www.softwhy.com/