Web Development Technology--jquery2 (event)

Source: Internet
Author: User

JQuery Event functions JQuery is specifically designed for event handling.

The jquery event handling method is the core function in jquery.

The event handler refers to the method that is called when certain events occur in the HTML. The term "triggered" (or "fired") by an event is often used.

The JQuery code is usually put into the

Instance
<HTML><Head>    <Scripttype= "Text/javascript"src= "Jquery.js"></Script>    <Scripttype= "Text/javascript">$ (document). Ready (function () { $("Button"). Click (function () { $("P"). Hide (); });    }); </Script></Head>    <Body>        <H2>This is a heading</H2>        <P>This is a paragraph.</P>        <P>This is another paragraph.</P>        <Button>Click Me</Button>    </Body></HTML>

In the example above, a function is called when the button's Click event is triggered:

$ ("button"). Click (function () {: Some code ...} )

This method hides all <p> elements:

$ ("P"). Hide ();
Functions in a separate file

If your site contains many pages, and you want your jquery function to be easy to maintain, put your jquery function in a separate. js file.

When we demonstrate jQuery in the tutorial, the function is added directly to the

Instance
<Head><Scripttype= "Text/javascript"src= "Jquery.js"></Script>    <Scripttype= "Text/javascript"src= "My_jquery_functions.js"></Script></Head>
JQuery Name conflict

jquery uses the $ symbol as a way to profile jquery.

Functions in some other JavaScript libraries, such as Prototype, also use the $ notation.

JQuery uses a method called noconflict () to resolve the problem.

var jq=jquery.noconflict (), which helps you to use your own name (such as JQ) instead of the $ symbol.

Conclusion

Because JQuery is specifically designed to handle HTML events, your code is more appropriate and easier to maintain when you follow these guidelines:

· Put all jQuery code in the event handler

· Place all event handlers in the document-ready event handler

· Put the JQuery code in a separate. js file

· Rename the JQuery library if there is a name conflict

JQuery Events

Here are some examples of the event methods in JQuery:

Event function

Bind function to

$ (document). Ready (function)

Bind a function to a document's Ready event (when the document finishes loading)

$ (selector). Click (function)

A click event that triggers or binds a function to the selected element

$ (selector). DblClick (function)

A double-click event that triggers or binds a function to the selected element

$ (selector). focus (function)

Trigger or bind a function to the Focusable event of the selected element

$ (selector). MouseOver (function)

Mouse hover event that triggers or binds a function to the selected element

Web Development Technology--jquery2 (event)

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.