Javascript 如何克隆和进行多个替换
这是我的JS,我正在克隆divJavascript 如何克隆和进行多个替换,javascript,jquery,regex,clone,Javascript,Jquery,Regex,Clone,这是我的JS,我正在克隆div#product-1,新克隆的标签目前已更改,我想知道如何进行其他替换 var clone = $('#product-1').clone(false); clone.find(".ingredientLabel").html(clone.find(".ingredientLabel").html().replace(/[0-9]+/g, counter)); $(clone).appendTo(".activeingredients"); 如何将id从produ
#product-1
,新克隆的标签目前已更改,我想知道如何进行其他替换
var clone = $('#product-1').clone(false);
clone.find(".ingredientLabel").html(clone.find(".ingredientLabel").html().replace(/[0-9]+/g, counter));
$(clone).appendTo(".activeingredients");
如何将id从product-1
更改为'product-'+计数器
在使用find()
使用find()后,.ingredientLabel
将成为将方法链接到的选定对象
链方法到
克隆
选择#产品-1
,然后再选择。ingredientLabel
没问题,很乐意帮助:)
clone.attr('id', 'product-'+counter).find(".ingredientLabel").html(clone.find(".ingredientLabel").html().replace(/[0-9]+/g, counter));