克隆 div 后,我无法选择我的选项。
克隆后,我希望能够选择选项并提供选定的课程。所以每个克隆的 div 都有选择的选项。
请检查我的演示并尝试克隆。
jQuery
var cloneCount = 0;
$("#add-address").click(function() {
$("#to-add-address").clone()
.attr("id", "to-add-address_Clone" + cloneCount)
.insertAfter("#to-add-address");
$("#clone", "#to-add-address_Clone" + cloneCount)
.attr("id", "clone_Clone" + cloneCount);
cloneCount++;
$('.options li a').bind('click',function () {
$('.options li a').removeClass('selected');
$(this).addClass('selected');
});
});
HTML
<ul>
<li id="to-add-address" class="outerDiv address" >
<div id="clone">
<label><input type="text" value="Address"><span class="input-edit"></span></label>
<label><input type="text" value="Address 2"><span class="input-edit"></span></label>
<label><input type="text" value="Town"><span class="input-edit"></span></label>
<label><input type="text" value="Contry"><span class="input-edit"></span></label>
<label><input type="text" value="Post Code"><span class="input-edit"></span></label>
<ul class="options">
<li class="home"><a href="javascript:void(0);">home</a></li>
<li class="work"><a href="javascript:void(0);">work</a></li>
<li class="other"><a href="javascript:void(0);">other</a></li>
<li class="delete"><a href="javascript:void(0);">delete</a></li>
</ul>
</div>
</li>
</ul>
<a href="javascript:void(0);" id="add-address">clone</a>