The bind () method usage instance in jquery _jquery

Source: Internet
Author: User

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/

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.