JQuery loads the data asynchronously and adds an event example

  • 2020-03-30 03:46:40
  • OfStack

A few months ago, I was involved in a project with a tree bar, and then I looked at a lot of plugins, and I felt a little bit troublesome.

At that time, the project was controlled by the tree bar, and the administrator could dynamically generate the tree bar from the database to add, delete and change the check operation, but with $(".xx ").click(); The way is not right.

1. Jq1.4.3 was used before, and jq1.7 can use the live() method to achieve this function


$( ' #div').live( ' click',function(){
//do stuff
});

2, jq1.7 above the use of the on method, the first property is the event, the second is the selector, the third is the method of execution


$(document).on("click","#d1",function(){
alert("bbbbb");
});

Related articles: