Self-written jQuery asynchronously loads data to add events _ jquery

Source: Internet
Author: User
This article mainly introduces a self-written jQuery Method for Asynchronously loading data and adding events. For more information about how to add events, see tree columns in a project a few months ago, I felt a little troublesome, so I wrote one by myself, and something went wrong when I wrote it.

At that time, the project implemented permission control through the tree column. The administrator can dynamically generate tree columns for data from the database for addition, deletion, modification, and query operations, but $ (". XX "). click (); The method does not work.

1. Previously, jq1.4.3 was used. jq1.7 can all use the live () method to implement this function.

The Code is as follows:


$ ('# P'). live ('click', function (){

// Do stuff

});


However, the live method also has events that are not supported. For example, for a toggle event, you can add a click event to it, and then simulate a trigger event.

The Code is as follows:


$ ('A'). live ('click', function (){
$ (This). toggle (function (){

Alert ("q11 ");
//
Alert ($ (this). attr ("id "));
$ (This). parent (). children ('ul '). show ();
}, Function (){
$ (This). parent (). children ('ul '). hide ();
});
$ (This). trigger ('click ');
/**
The previously bound click event triggers the toggle event only after the click event is clicked. Therefore, a simulated click event is added to the event and you do not need to click to start directly.
**/
});


2. jq1.7 and later use the on method. The first attribute is the event, the second is the selector, and the third is the execution method.

The Code is as follows:


$ (Document). on ("click", "# d1", function (){
Alert ("bbbbb ");
});

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.