【发布时间】:2018-12-29 14:49:04
【问题描述】:
我希望能够在单击复选框时克隆它,并且克隆的复选框将被取消选中。选中克隆复选框后,它将自身克隆并重复进程。
<section class="misc">
<div class="row">
<label class="label"><input type="checkbox" class="others"> Others:</label>
</div>
<div class="row">
<div class="col-md-6"><input type="text" class="form-control" placeholder="Others"/></div>
</div>
</section>
<div class="sth"></div>
<!-- Clone the "Others" checkbox with textbox when the original checkbox is checked. I want each subsequent clone to be unchecked, then clone itself.. -->
<script>
$(".others").change(function(){
if($(this).is(':checked'))
{
var clone=$(this).parents('section').clone();
$('.sth').html(clone);
}
});</script>
现在,我只能克隆原始的,并且克隆的复选框被选中而不是未选中。
Jsfiddle:http://jsfiddle.net/cLkvxydh/
【问题讨论】:
标签: javascript jquery checkbox onchange