【发布时间】:2012-07-21 22:43:03
【问题描述】:
很难弄清楚如何使用克隆的 jQuery 对象为 div 内容中的每个 id 属性添加增量值。
===================== HTML======================
<div class="upload-file-container">
<div class="uploadFile left clearfix">
<input type="file" id="FileUpload1">
<table id="RadioButtonList1">
<tbody>
<tr>
<td><input type="radio" value="Resume" id="RadioButtonList1_1">
<label for="RadioButtonList1_1">Resume</label></td>
<td><input type="radio" value="Letter of Recommendation" id="RadioButtonList1_2">
<label for="RadioButtonList1_2">Letter of Recommendation</label></td>
<td><input type="radio" value="Other" id="RadioButtonList1_3">
<label for="RadioButtonList1_3">Other</label></td>
</tr>
</tbody>
</table>
</div>
<a href="javascript:;" class="remove left">Remove</a> </div>
<div class=""><a class="plus" href="javascript:;">plus one</a></div>
=====================JQUERY =====================
//Cloning upload file control
$('.remove').live('click', function () {
if (confirm("Are you sure you wish to remove this item?")) {
$(this).parent().slideUp('fast', function () {
$(this).remove();
});
}
return false;
});
$('.plus').click(function () {
console.log('cloning');
var divCloned = $('.upload-file-container:first').clone();
divCloned.hide().insertAfter('.upload-file-container:last').slideDown('fast');
return false;
});
【问题讨论】:
-
它看起来不像那么多代码 - 为什么不在这里发布它并提供小提琴链接作为参考。如果 jsfiddle 被关闭了怎么办?我们将无法为您提供帮助:)
-
我不清楚你在问什么问题。
-
对我来说,不清楚您为什么要这样做 - 请注意您的示例中甚至没有
name属性。不完整吗? -
每次 '.upload-file-container' 获得克隆时,ID 必须与第一个 '.upload-file-container' 不同
-
如果您可以向我们解释您想要的效果是什么以及问题究竟出在哪里 - 这样给您提供建议会更容易...
标签: clone jquery jquery-click-event