[英]Persist checkbox state while jsp reload
我有一些代码,当我从控制器回来后重新加载jsp页面时,我想保留多个复选框状态(已选中)。我可以在会话中成功检索选定的值,但无法选中复选框。 我的代码段如下:
<%!public String portarray[] = null;%>
<%if (request.getSession().getAttribute("portselected") != null) {
portarray = (String[]) request.getSession().getAttribute("portselected");
for (int i = 0; i < portarray.length; i++) {%>
alert(
<%=portarray[i]%>
);
$("#\"removebasket"+<%=portarray[i]%>+"\"").attr("checked", true);
$('#removebasket13989')[0].checked = true;
首先使用document.ready仅在页面完全加载时执行此操作。 另外,使用.prop()设置检查状态
// only when page fully loads
$(document).ready(function() {
// use prop
$('.myCheckbox').prop('checked', true);
});
您还应该确保$("#\\"removebasket"+<%=portarray[i]%>+"\\"")
正确无误,方法是在重新加载页面时查看其源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.