[英]Get count and values of checkbox on click of it in the textbox and on uncheck the value should be removed and count should decreased in textbox
下面是html代碼,我想在id ='selchk'的文本框中獲取用逗號分隔的復選框的值,並在id ='getcnt'的文本框中獲取單擊的復選框的計數,並在未選中的情況下應刪除該值並應該使用jquery減少計數。我已經嘗試過但沒有達到結果。需要幫助
<input type='checkbox' class='chk' value='1'>
<input type='checkbox' class='chk' value='2'>
<input type='checkbox' class='chk' value='3'>
<input type='checkbox' class='chk' value='4'>
<input type='checkbox' class='chk' value='5'>
<input type='checkbox' class='chk' value='6'>
<input type='text' class='getcnt' id='getcnt'>
<input type='text' class='selchk' id='selchk'>
var $boxes = $('input[type=checkbox]'),
$count = $('#getcnt'),
$values = $('#selchk');
$boxes.click(function() {
var values = [];
var checked =0;
$boxes.each(function() {
if (this.checked) {
values.push(this.value);
checked++;
}
});
$count.attr('value',checked);
$values.attr('value',values.toString());
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.