A few months ago, I involved a tree bar in a project and read a lot of plug-ins. I felt a little troublesome. So I wrote one by myself, and there was a problem 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.
Copy codeThe Code is as follows:
$ ('# Div'). 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.
Copy codeThe 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.
Copy codeThe Code is as follows:
$ (Document). on ("click", "# d1", function (){
Alert ("bbbbb ");
});