Возможно ли в checkselect прописать вместо отображения количества выбранных строк процентное отношение, где строка = 10% ???
Как это можно решить на примере?
Код:
<script src="checkselect"></script>
<div class="checkselect" id="checkselect-1">
<div class="checkselect__backdrop" data-select="backdrop"></div>
<button type="button" class="checkselect__trigger" data-checkselect="trigger">
Отметьте галочкой
</button>
<fieldset>
<legend> T </legend>
<label><input type="checkbox" name="brands[]" value="10%"> Системность</label>
<label><input type="checkbox" name="brands[]" value="20%"> Порядок</label>
<label><input type="checkbox" name="brands[]" value="30%"> Осмысленность</label>
<label><input type="checkbox" name="brands[]" value="40%"> Анализ</label>
<label><input type="checkbox" name="brands[]" value="50%"> Чувства скрыты</label>
<label><input type="checkbox" name="brands[]" value="60%"> Аргументы</label>
<label><input type="checkbox" name="brands[]" value="70%"> Целеустремлённость</label>
<label><input type="checkbox" name="brands[]" value="80%"> Деловитость</label>
<label><input type="checkbox" name="brands[]" value="90%"> Структура</label>
<label><input type="checkbox" name="brands[]" value="100%"> Костность</label>
</fieldset>
</div>
<style type="text/css">
body{
background: (transparent) 50% 0 no-repeat;
}
.checkselect {
position: relative;
display: inline-block;
min-width: 200px;
text-align: left;
}
.checkselect-control {
position: relative;
padding: 0 !important;
}
.checkselect-control select {
position: relative;
display: inline-block;
width: 100%;
margin: 0;
padding-left: 5px;
height: 30px;
}
.checkselect-over {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
cursor: pointer;
}
.checkselect-popup {
display: none;
box-sizing: border-box;
margin: 0;
padding: 0;
width: 100%;
height: auto;
max-height: 200px;
position: absolute;
top: 100%;
left: 0px;
border: 1px solid #dadada;
border-top: none;
background: #fff;
z-index: 9999;
overflow: auto;
user-select: none;
}
.checkselect label {
position: relative;
display: block;
margin: 0;
padding: 4px 6px 4px 25px;
font-weight: normal;
font-size: 1em;
line-height: 1.1;
cursor: pointer;
}
.checkselect-popup input {
position: absolute;
top: 5px;
left: 8px;
margin: 0 !important;
padding: 0;
}
.checkselect-popup label:hover {
background: #03a2ff;
color: #fff;
}
.checkselect-popup fieldset {
display: block;
margin: 0;
padding: 0;
border: none;
}
.checkselect-popup fieldset input {
left: 15px;
}
.checkselect-popup fieldset label {
padding-left: 32px;
}
.checkselect-popup legend {
display: block;
margin: 0;
padding: 5px 8px;
font-weight: 700;
font-size: 1em;
line-height: 1.1;
}
</style>
<script src="https://snipp.ru/cdn/jquery/2.1.1/jquery.min.js"></script>
<script>
(function($) {
function setChecked(target) {
var checked = $(target).find("input[type='checkbox']:checked").length;
if (checked) {
$(target).find('select option:first').html('Выбрано: ' + checked);
} else {
$(target).find('select option:first').html('Выберите из списка');
}
}
$.fn.checkselect = function() {
this.wrapInner('<div class="checkselect-popup"></div>');
this.prepend(
'<div class="checkselect-control">' +
'<select class="form-control"><option></option></select>' +
'<div class="checkselect-over"></div>' +
'</div>'
);
this.each(function(){
setChecked(this);
});
this.find('input[type="checkbox"]').click(function(){
setChecked($(this).parents('.checkselect'));
});
this.parent().find('.checkselect-control').on('click', function(){
$popup = $(this).next();
$('.checkselect-popup').not($popup).css('display', 'none');
if ($popup.is(':hidden')) {
$popup.css('display', 'block');
$(this).find('select').focus();
} else {
$popup.css('display', 'none');
}
});
$('html, body').on('click', function(e){
if ($(e.target).closest('.checkselect').length == 0){
$('.checkselect-popup').css('display', 'none');
}
});
};
})(jQuery);
$('.checkselect').checkselect();
</script>