gpt4 book ai didi

jquery - 使用 Jquery 克隆输入但具有空值

转载 作者:行者123 更新时间:2023-11-27 22:48:08 25 4
gpt4 key购买 nike

我有大量的 HTML:

<div class="bundle" id="bun">
<div>
<label for="title">title:</label><input name="name" id="name" value="led zeppelin III" type="text">
</div>
<div>
<label for="content">content:</label><textarea type="textarea" cols="100" rows="3" name="content" id="content">composed largely at a remote cottage in wales known as Bron-Yr-Aur, this work represented a maturing of the band's music towards a greater emphasis on folk and acoustic sounds. this surprised many fans and critics, and upon its release the album received rather indifferent reviews</textarea>
</div>
<div>
<label for="url">url for image:</label><input name="url" id="url" value="http://www.bob.co.il/wp-content/themes/CMOTA-1.0/demo-images/3.jpg" type="text">
</div>
<img src="http://www.bob.co.il/wp-content/themes/CMOTA-1.0/demo-images/3.jpg" alt="led zeppelin III" height="272">
</div>

我正在使用 clone() jquery 方法将此批量复制到表单末尾:

var newElem = $('#bun' + val).clone().attr('id', 'bun' + newval);
newElem.children('input:first').attr('name', 'title' + newval).attr('id', 'title' + newval);
newElem.children('textarea:first').attr('name', 'content' + newval).attr('id', 'content' + newval);
newElem.children('input:nth-child(2)').attr('name', 'url' + newval).attr('id', 'url' + newval);
$('#bun' + val).after(newElem);

它确实有效,但我只想克隆“bun”元素的内容,而没有输入值和图像的 src。我应该如何处理这个问题?

谢谢。

最佳答案

var newElem = $('#bun' + val).clone().attr('id', 'bun' + newval);
newElem.children('input:first').attr('name', 'title' + newval).attr('id', 'title' + newval);
newElem.children('textarea:first').attr('name', 'content' + newval).attr('id', 'content' + newval);
newElem.children('input:nth-child(2)').attr('name', 'url' + newval).attr('id', 'url' + newval);
$('#bun' + val).after(newElem);
newElem.find('input,textarea').val('');

关于jquery - 使用 Jquery 克隆输入但具有空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5769972/

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