后台怎么将值传给复选框?????? 有没有直接传数组的???
<tr>
<th><label class="text">选择教师:</label></th>
<td>
<ul style="width: 100%">
<input type="hidden" value="${tids}" name="tids"/>
<#list typeList as teacher>
<li style="width: 33%; display: block; float: left;"><input
type="checkbox" id="teacher_ids_${teacher.type_id}" name="teacher_ids"
value="${teacher.type_id }" /> ${teacher.name}</li> </#list>
<script>
var idstr = document.getElementsByName("tids")[0].value;
var strs= new Array();
ids=idstr.split(",");
for(var i=0;i<ids.length;i++){
var checkbox = document.getElementById("teacher_ids_"+ids[i]);
checkbox.checked="checked";
//checkbox.setAttribute("checked", true);
}
</script>
</ul></td>
</tr>
本文介绍了一种在后台将值传递给前端复选框的方法,通过将已选中的值作为数组传递并在前端使用JavaScript进行处理,使得对应项默认被选中。此方法适用于需要预填充复选框选中状态的场景。
1326

被折叠的 条评论
为什么被折叠?



