【发布时间】:2018-05-23 08:16:41
【问题描述】:
我在选中的复选框上增加了进度条。它适用于单组复选框,但对于多组复选框,它不能按方面工作。
我想要什么
如果我使用多张卡,并且每张卡中会有多个复选框,它们都应该单独工作
$('.card').each(function(index, el) {
// console.log( $(this).find('input[type="checkbox"]').length );
var chkLength = $(this).find('input[type="checkbox"]').length;
var max = 100;
var div = max / chkLength;
$('.scrumboard .card .task-quantity').text('0/' + chkLength);
// $(this).find('input[type="checkbox"]').append("<div>" + div +" </div>");
$(this).find('input[type="checkbox"]').attr('value', div);
});
// Progress bar code
val = 0;
$('.card .new-control-input').on('change', function(event) {
if ($(this).is(':checked')) {
console.log('chk');
// perc += parseInt($(this).val());
// $(this).attr('checked', '');
console.log(val += parseInt($(this).val()));
} else {
console.log('nchk');
console.log(val -= parseInt($(this).val()));
}
$(".progress .progress-bar").each(function(index, el) {
$(this).css("width", val + "%");
});
})
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="card">
<input type="checkbox" class="new-control-input">
<input type="checkbox" class="new-control-input">
<input type="checkbox" class="new-control-input">
<input type="checkbox" class="new-control-input">
<input type="checkbox" class="new-control-input">
<div class="progress">
<div class="progress-bar bg-primary" role="progressbar" style="" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<p class="task-quantity"></p>
</div>
<div class="card">
<input type="checkbox" class="new-control-input">
<input type="checkbox" class="new-control-input">
<input type="checkbox" class="new-control-input">
<input type="checkbox" class="new-control-input">
<input type="checkbox" class="new-control-input">
<div class="progress">
<div class="progress-bar bgbbg-primary" role="progressbar" style="" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<p class="task-quantity"></p>
</div>
链接
【问题讨论】:
-
请添加一些您的代码,期望与它现在在做什么?
-
给我一些时间
-
@RoryMcCrossan 更新问题
-
感谢您的编辑。我在下面为您添加了答案