gpt4 book ai didi

javascript - 选中时触发复选框

转载 作者:行者123 更新时间:2023-12-02 19:30:32 24 4
gpt4 key购买 nike

Possible Duplicate:
How to listen to when a checkbox is checked in Jquery

我正在使用 JQuery 动态创建许多复选框,如下所示。

     function createCheckbox(len){

for(var i = 0; i < len; i++){
$('#checkboxes').append('<input type="checkbox" ' + 'id=' + i + '></input>');
}
return;
}

在 HTML 中,我有:

<div id="checkboxes"></div>

我的目标是每当选中一个复选框时,就能够将其 id(或值)发送到此函数:

function hideColumn(columnIndex){
$('#chart2 td:nth-child(' + (columnIndex+1) + ')').hide();
return;
}

它将能够处理隐藏表中特定列的逻辑。有人可以帮我吗?谢谢

最佳答案

也许你可以尝试这个,只需修改 createCheckbox 函数即可:

function createCheckbox(len){
for(var i = 0; i < len; i++){
$('<input type="checkbox" ' + 'id=' + i + '></input>').on('change', function(e) {
if (this.checked) {
hideColumn(this.id);
}
}).appendTo($('#checkboxes'));
}
return;
}

关于javascript - 选中时触发复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11544195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com