jquery bind the click event

 To describe the problems encountered under: before the project <li> elements under <ul> element in the page is written dead, so give <li> element directly bind click event $ ( "li") click (. function () {}), and packaged into a common assembly js. Now requires the next <ul> <li> dynamic, i.e., back through the interface needs to be inserted into the <ul> by append () method. So encapsulated $ ( "li"). Click (function () {}), if used before it occurs not on the binding problem. Because to the <li> to bind click event, <li> element does not exist. Then immediately thought of the solution after the append () <li> element to the <li> element to rebind the click () event, but in this case, too much repetitive code. So, after a lot of inquiries, to find a solution is to give <ul> element is bound click () event, $ ( "ul"). On ( "click", "li", function () {}) , this is the case, "it is equivalent to the <li> elements under <ul> bindings click () incident.

Guess you like

Origin www.cnblogs.com/web-cuicui/p/12106219.html