jQuery_ copy operation

Copy operation code:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>文档处理_复制操作</title>
        <script type="text/javascript" src="js/jquery-1.11.0.min.js" ></script>
        <script>
            /**
             * Demand
             * 1. Click apple, orange or pineapple list item, click the copied content and appended to the end of ul
             Content * 2. Click apple, orange or pineapple list item, click the copied content and appended to the end of ul, after the required copy also has the ability to replicate
             */
            
            /**
             * Analysis Method:
             * 1.clone (): clone matched DOM Elements and select the clones.
             * 2.clone (): all its elements and event handlers and check copies of these clones
             */
        
             $ ( Function () {
                  // Click li list items, will be elected clicked ul li append to the end of 
                $ ( " ul li " ) .click ( function () {
                     // $ (the this) .clone (). The appendTo ( "ul"); // copy the current node clicks, and append it to the <ul> element 
                    $ ( the this ) .clone ( to true ) .appendTo ( " ul " ); // after setting the parameters true, after copying the contents also has a click event 
                })   
              });
        </ Script > 
    </ head > 
    < body > 
        < the p- title = "Choose your favorite fruit."  > Your favorite fruit? </ The p- > 
        < ul > 
          < li title = 'apple' > Apple </ Li > 
          < Li title = 'orange' > orange </ Li > 
          < Li title = 'pineapple' > pineapple </ Li > 
        </ UL > 
    </body>
</html>

operation result:

 

 After clicking repeatedly li:

 

 

 

 

 

Note: clone () parameter which affects whether something is true to copy out whether the same as the original property, that is true if you click on the orange, generates an orange, but orange you click on the new generation, will copy; the contrary there is no parameter, the click is not a replication of the newly generated functions.

 

 

Guess you like

Origin www.cnblogs.com/tkg1314/p/11978329.html