每当我尝试克隆div的时候,第一次div检查广播自动未选中。
为什么会这样?任何我做错的事..
用户检查了无线电,而不是单击添加按钮,那一次第一次检查的值消失了,但是不应取消选中。
这是代码。
var count = 1;
var is = 0;
var isx = 1;
$(function () {
$("body").on('click', '.btn-add', function (e) {
count++;
e.preventDefault();
if (count > 5)
return;
var controlForm = $('.miuplod:first'),
currentEntry = $(this).parents('.uploadgroup:first'),
newEntry = $(currentEntry.clone()).appendTo(controlForm);
newEntry.find('input').val('');
newEntry.find('input:radio').attr('checked', false);
newEntry.find('input:radio[name="chotype' + is + '"]').attr('name', 'chotype' + isx);
newEntry.find('input:radio[name="align' + is + '"]').attr('name', 'align' + isx);
is++;
isx++;
controlForm.find('.uploadgroup:not(:last) .btn-add')
.remove()
.removeClass('btn-success');
//.html('<span class="glyphicon glyphicon-minus">-</span>');
}).on('click', '.btn-remove', function (e) {
$(this).parents('.uploadgroup:first').remove();
e.preventDefault();
count--;
is--;
isx--;
return false;
});
});
请帮助我..这是一个jsfiddle link。
最佳答案
您需要修改克隆的元素,然后附加它。
newEntry = currentEntry.clone();
//Do your operation
newEntry.appendTo(controlForm);
Update fiddle
关于javascript - 在附加的div上,第一个div的电台已选中自动未选中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42618574/