javascript copy 改變id

  • 45
  • 0

javascript copy 改變id

var cloneCount = 1;;
   $("button").click(function(){
      $('#id')
          .clone()
          .attr('id', 'id'+ cloneCount++)
          .insertAfter('[id^=id]:last') 
           //            ^-- Use '#id' if you want to insert the cloned 
           //                element in the beginning
          .text('Cloned ' + (cloneCount-1)); //<--For DEMO
   }); 

https://stackoverflow.com/questions/10126395/how-to-jquery-clone-and-change-id