gpt4 book ai didi

javascript - 从 html 到 Javascript 获取 ID 数组

转载 作者:行者123 更新时间:2023-12-03 10:41:51 24 4
gpt4 key购买 nike

如何在 JS 中获取并循环 deacTraining 值?在此给定代码中,在获取 deacTraining 的值后,复选框的长度为 0。

html代码片段

<c:forEach var="acBatch" items="${batchBeanAll}" varStatus="loop">
<c:if test="${acBatch.getBatchStatus() == 'Active'}">
<c:set var="counter" value="${counter + 1}" scope="page"/>
<tr>
<td scope='col'><input id="deacTraining${loop.index }" type='checkbox' name='users'value='${acBatch.getBatchCode()}'/></td>
<td scope='col'>${acBatch.getBatchDescription()}</td>
<td scope='col'>${acBatch.getBatchSize()}</td>
<td scope='col'>${acBatch.getBatchStatus()}</td>
</tr>
</c:if>

<input value="Continue" type="submit" onclick="return checkDeactivateTraining();"/>

js代码

<script>
function checkDeactivateTraining(){
var checkboxes = document.getElementsByName('deacTraining');
for (var i=0; i<checkboxes.length; i++){
if (checkboxes[i].checked)
return true;
}

alert("Please select a training to deactivate.");
return false;
}
</script>

最佳答案

复选框的名称usersid是“deacTraining...”。更改:

document.getElementsByName('deacTraining');

至:

document.getElementsByName('users');

关于javascript - 从 html 到 Javascript 获取 ID 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28738669/

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