【发布时间】:2022-01-10 16:38:12
【问题描述】:
所以,我设法创建了一系列勾选的行并将其链接到一个按钮。单击按钮时,所有单击的行都将在新选项卡中打开。
现在我的问题是,我没有设法使所有内容都被选中。我尝试了各种将所选行放入数组的方法,而有效的方法是这段代码,所以我将继续使用它:
toggleTick_Change()
var chktArr =[];
function toggleTick_Change(){
chktArr = $('.single-row-checkbox:checkbox:checked').map(function(){
return $(this).val();
}).get();
console.log('the checked values are: ' + chktArr);
$('#conditional-part').show();
}
但是当另一个复选框被选中时,仍然无法全部选中。
以下是打开新标签的按钮:
function btnPrintCNT_Click(){
console.log('This is from button , the checked values are: ' + chktArr);
for(let i = 0 ; chktArr.length > i ; i++){
window.open('?mod=admin&action=consignment&id=' + chktArr[i]);
}
}
复选框 HTML 代码
<input type="checkbox" id="chkAll" value="{$rows.id}" name="chktArr" style="width: 15px; height: 15px;" class="all-row-checkbox" onchange="toggleTick_Change()" />
<input type="checkbox" id="chkT{$rows.id}" value="{$rows.id}" name="chktArr" style="width: 15px; height: 15px;" class="single-row-checkbox" onchange="toggleTick_Change()" />
按钮 HTML 代码:
<div class="input-group " role="group" aria-label="..." style="width: 85px; margin-top: 2px; " >
<span class="input-group-btn">
<button id="btnPrintCNT" type="button" class="btn btn-sm btn-primary"
style="margin: 2px; width: 100px; margin-left: 20px; float: left;"
onclick="javascript:btnPrintCNT_Click()">CNT</button>
</span>
</div>
非常感谢任何建议。
【问题讨论】:
-
你为什么不只是循环检查选中的复选框?为什么需要数组?
-
@epascarello 因为我想从选定的行中调用 pdf 文件,所以我将选定行的 id 放入数组中
标签: javascript html jquery css checkbox