27. Jquery events and 27jquery events

Source: Internet
Author: User

27. Jquery events and 27jquery events

Jquery events

In javascript, the event calling methods are onclick and onmouseover. In jquery, you do not need to write the previous on

Bind () method

Bind events to elements

$ ("# Id"). bind ("click", function () {// bind a click event for the id alert ("OK ");});

Events bound using the bind () method are multicast event delegates, that is, events that are redefined do not overwrite the previous event.

// Two events can be executed in sequence $ ("# id "). bind ("click", function () {alert ("1") ;}); $ ("# id "). bind ("click", function () {alert ("2 ")});

One () method

Bind one-time event

// Only one click operation will not be executed next time $ ("# id "). one ("click", function () {alert ("a"); return false ;});

Unbind () method

Delete events and unbind

$ ("# Id "). unbind (); // delete all events of the id $ ("# id "). unbind ("click"); // delete all click events of the id

Quick events

Basic Support for removing on from javascript events

Click () method

Click Event

$ ("# Id "). click (); // if the function body is not written, the event is triggered immediately $ ("# id "). click (function () {// This Is A click event });

Dbclick () method

Double-click event

$ ("# Id"). dbclick (); // trigger event $ ("# id"). dbclick (function () {// double-click and execute });

Focus () method

Focus

$ ("# Id"). focus (); // trigger $ ("# id"). focus (function () {// execute after obtaining focus });

Blur () method

No focus

$ ("# Id "). blur (); // triggers the event of losing focus $ ("# id "). blur (function () {// execute after the focus is lost });

Change () method

Change

$ ("# Id"). change (); // trigger the change event $ ("# id"). change (function () {// execute after change });

Mouseover () method

Move the mouse in

$("#id").mouseover();$("#id").mouseover(function(){});

Mouseout () method

Move the mouse out

$("#id").mouseout();$("#id").mouseout(function(){});

Submit () method

Submit Form

$("#id").submit(); $("#id").submit(function(){});

Hover () method

Used to solve the problems of mouseover and mouseout

// The two functions correspond to the moving and removing functions respectively $ ("div "). hover (function () {$ ("div" ).html ("ah He came") ;}, function () {$ ("div" ).html ("the call, scared to death, finally left! ")});

Toggle () method

Execute each function in sequence.

$("#div").toggle(    function(){        $("#div").css({ "width": "100px" });    },    function(){        $("#div").css({ "width": "200px" });    },    function(){        $("#div").css({ "width": "300px" });    });

Jquery event object

Jquery eventmerges the differences between different browsers. For example, you can use event.tar get in a browser to obtain the trigger without judging whether the browser uses srcElement.

$ ("# Div "). click (function (e) {alert (e. type); // returns the event name click alert(e.tar get); // returns the alert (e. altKey); // returns whether alt is pressed by alert (e. screenX );//... events in js });

 

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.