JQuery on () method problem

Source: Internet
Author: User

<! DOCTYPE html>


<script src= "https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js" >
</script>
<script>
Function F1 (i) {
Alert ("the paragraph is clicked. "+i.data.this);
}

$ (document). Ready (function () {
$ ("p"). on ("click", {this:5},f1);
});
</script>

<body>

<p> Click this paragraph. </p>

</body>

. On (events [, selector] [, data], handler (eventobject))

handlerThe argument must be a function (or false value, see Below) unless you pass an object to the events Argument. You can provide an anonymous handler for the .on() call, as in the example above, or you can declare a function and then use the function name as an argument:

12 function notify() { alert("clicked"); }$("button").on("click", notify);

If data the parameter is given .on() and is not null or undefined , then each time the event is triggered, it event.data is passed to the Handler. dataThe parameter can be of any type, but if it is a string type, then selector the parameter must be provided, or explicitly passed null , so that the data parameter is not mistaken for a selector. It is best to use an object (a key-value pair), so you can pass multiple values as Attributes.

jquery 1.4, The same event handler can be bound to an element multiple Times. This event.data is especially useful for using features, or for using unique data in Closures. For example:

123 function greet(event) { alert("Hello "+event.data.name); }$("button").on("click", { name: "Karl" }, greet);$("button").on("click", { name: "Addy" }, greet);

JQuery on () method problem

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.