cuốn sách gpt4 ai đã làm

javascript - Accordion 式 list 计数器 document.form[]

In lại Tác giả: Walker 123 更新时间:2023-11-28 04:34:57 33 4
mua khóa gpt4 Nike

我有 3 种不同的表单,其中复选框数量不同,每个部分基本上代表一个表单,因此当用户选择该部分中的复选框时,它会显示他们在该部分的总金额中 checkout 了多少

HTML

































































































Xem sitemap của VNExpress

jquery

$(hàm(){
var e = document.forms[0];
var numQuestion;
var i;
var formName = $(this).e;
for(i = 0; i < e.length; i++){
numQuestion = e.getEle**mentsByTagName('label');
console.log(numQuestion.length);
}

$('#' + formName).closest('.panel-heading').find('.numOfQuestions').text('/' + e.length);

var $checkboxes = $('input[type="checkbox"], #form1');

$checkboxes.change(function(){
var countCheckedCheckboxes = $checkboxes.filter(':checked').length;
$(this).closest('.panel-heading').find('.count-checked-checkboxes').text('Name of Section ' + countCheckedCheckboxes);
});

});

my progress so far

câu trả lời hay nhất

这就是我想出的可以完成这项工作的方法。为了清晰起见,我认为您可以按照它进行任何必要的修改。

// --- when user changes a checkbox ---
$(document).on('change', 'input[type="checkbox"]', function(e) {
// --- get the form name ---
var $form = $(this).closest('form');
var formName = $form.attr('id');

// --- count the checkboxes for this form ---
var totalCheckboxes = $form.children('input[type="checkbox"]').length;

// --- place count value in the 'numOfQuestions' p ---
var $panel = $form.closest('.panel-default');
$panel.find('.numOfQuestions').text('/' + totalCheckboxes);

// --- count total checkboxes checked ---
var countCheckedCheckboxes = $form.children('input[type="checkbox"]:checked').length;

// --- place checked count in 'count-checked-checkboxes' p ---
$panel.find('.count-checked-checkboxes').text('Name of Section '+countCheckedCheckboxes);

});

关于javascript - Accordion 式 list 计数器 document.form[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44291153/

33 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress