jQuery clone duplicate IDs

后端 未结 9 1849
醉梦人生
醉梦人生 2020-12-04 19:03

I have an HTML element with a large collection of unordered lists contained within it. I need to clone this element to place elsewhere on the page with different styles adde

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 19:41

    FWIW, I used Dario's function, but needed to catch form labels as well.

    Add another if statement like this to do so:

    if(element.htmlFor){
    var matches = element.htmlFor.match(/(.+)_\d+/);
    if(matches && matches.length >= 2)            // Captures start at [1].
      element.htmlFor = matches[1] + "_" + cur_num;
    }
    

提交回复
热议问题