0
我的代码出现了一些奇怪的现象。我有两个按钮,一个是类.add和.remove,其中有一个复选框,由于按下了哪个按钮而打开和关闭,所以如果使用删除按钮删除选中的复选框,否则复选框会取消选中,问题I '当时你重复使用.remove按钮时,它添加了checked属性,但复选框不会显示它已被选中,但在html中它的属性就在那里。没有人知道如何解决这个问题复选框已检查属性,但不显示已选中
$('.variations_grid').on('click','.add', function(e) {
var elements = $(this).closest('tr').find('td');
var isDisabled = $(this).closest('tr').find('button.remove').is(':disabled')
if(isDisabled) {
$(this).closest('tr').removeClass('remove')
$(this).closest('tr').find('.add').attr('disabled', 'disabled');
$(this).closest('tr').find('button.remove').removeAttr('disabled');
$(this).closest('tr').find('.delete:checkbox').attr('checked', false);
} else {
$(this).closest('tr').before(template);
}
$.each(elements, function(index, element) {
if(index > 1) {
//$(this).find('select').removeAttr('disabled');
//$(this).find('input').removeAttr('disabled')
}
});
});
$('.variations_grid').on('click','button.remove', function(e) {
var elements = $(this).closest('tr').find('td');
$(this).closest('tr').addClass('remove')
$(this).closest('tr').find('.add').removeAttr('disabled');
$(this).closest('tr').find('.remove').attr('disabled', 'disabled');
$(this).closest('tr').find('.delete:checkbox').attr('checked', 'checked');
$.each(elements, function(index, element) {
if(index > 1) {
//$(this).find('select').attr('disabled', 'disabled');
//$(this).find('input').attr('disabled', 'disabled')
}
});
});
HTML
<button class="btn btn-default btn-block add" type="button" disabled="disabled"> <span class="glyphicon glyphicon-plus-sign"></span> </button>
<button class="btn btn-default btn-block remove" type="button"> <span class="glyphicon glyphicon-minus-sign"></span> </button>
<input name="delete" type="checkbox" class="delete" />
啊谢谢你另一个要记住谢谢你的回答它的窍门 – ONYX 2014-10-05 06:00:40
@KDM很好,很高兴帮助你... – 2014-10-05 06:01:07