gpt4 book ai didi

jquery - 如何将元素 id 值更新为值+文本?

转载 作者:行者123 更新时间:2023-12-01 07:48:19 24 4
gpt4 key购买 nike

我想将 div 的所有子 ID 设置为其 ID + 数字。这是一个不起作用的代码示例,但它应该可以让我了解我想要它做什么。

对于每个 child ,我想将 ID 属性更改为 ID + input_count。

我这样做是因为我克隆了一个包含一些子元素的 div,并且我想将克隆计数附加到每个子元素 div id 上以保持唯一性。

$(parentDiv).children().attr('id', this.attr('id')+inputs_count);

最佳答案

试试这个:

$(parentDiv).children().each(function()
{
$(this).attr('id', $(this).attr('id')+inputs_count);
});

示例:http://jsfiddle.net/nkgtf278/1/

关于jquery - 如何将元素 id 值更新为值+文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33180571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com