Home > Web Front-end > JS Tutorial > A brief analysis of JS delegate and live_javascript skills

A brief analysis of JS delegate and live_javascript skills

WBOY
Release: 2016-05-16 17:07:59
Original
1442 people have browsed it

There are two methods in jquery that can be used to bind automatically appended DOM objects. They are live and delegate. In fact, these two methods are a variant of the bind method. When it comes to fixed DOM objects, We usually just use bind, but for DOM objects dynamically generated by objects, using bind is powerless. At this time, live and delegate come into play, haha.

The live method is used to bind a certain object (of a certain type) and bind methods to them

Copy code The code is as follows: .live("click", function () {
                         alert($(this).       ); live("click", function () {
                              alert($(this).html()); Sub-objects under a certain class) object, bind methods to the sub-object (delegate the sub-object, let the sub-object have a certain method, haha)





Copy code

The code is as follows:

$("#list").delegate("td ", "click", function () {

                                                                                                                            ; The completed code of the DEMO below:
Copy code


The code is as follows:






script id="listTemplate" type="text/html">
                                                                                                                                                   td>
> var reg = new RegExp("\[([^\[\]]*?)\]", 'igm'); //i g m refers to specifying case-sensitive matching, global matching and multi-line respectively match.

          $(function () {
                                                                                                                                                                                                                                           ; );
          });

                                                                                                                                                                                                             key) { return { 'UserImg': '1', 'UserName': 'zhang', 'UserID': '1' }[key]; });                                     $("#list").append(source );

          });

});









Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template