Answer the question
In order to leave comments, you need to log in
Are the values displayed one by one, instead of one?
There is a code:
Html:
<label class="checkbox"><input type="checkbox" value="значение 1">checkbox 1</label><br>
<label class="checkbox"><input type="checkbox" value="значение 2">checkbox 2</label><br>
<label class="checkbox"><input type="checkbox" value="значение 3">checkbox 3</label><br>
<label class="checkbox"><input type="checkbox" value="значение 4">checkbox 4</label>
<p>
<button id="btn" class="btn btn-sm btn-default">Получить отмеченные</button>
</p>
<p id="result" class="text-success"></p>
$(document).ready(function() {
$('#btn').click(function(){
$('#result').html('');
var heig = [];
$("input:checkbox:checked").each(function(){
heig.push($(this).val());
$('#result').append(heig[0] + ' and '+(heig.length-1)+' more')});
});});
Answer the question
In order to leave comments, you need to log in
It is enough just to take the output from the loop:
$(document).ready(function() {
$('#btn').click(function(){
$('#result').html('');
var heig = [];
$("input:checkbox:checked").each(function(){
heig.push($(this).val());
});
$('#result').append(heig[0] + ' and '+(heig.length-1)+' more');
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question