记录一下,就直接贴代码了。
兴趣:<input type="checkbox" name="happys" value="打篮球" id="checkb1" >打篮球 <input type="checkbox" name="happys" value="踢足球" id="checkb2">踢足球 <input type="checkbox" name="happys" value="羽毛球" id="checkb3">羽毛球 <input type="checkbox" name="happys" value="游泳" id="checkb4">游泳 <input type="checkbox" name="happys" value="跑步" id="checkb5">跑步<br> <input type="hidden" value="${stu.happy}" id="happys">
<script type="text/javascript"> $(function () { var arry = new Array(); /*截取字符串 生成数组*/ arry=$("#happys").val().split(","); for (var i=0;i<=arry.length;i++){ if (arry[i]=="打蓝球"){ $("#checkb1").attr("checked","true"); }else if (arry[i]=='踢足球'){ $("#checkb2").attr("checked","true"); }else if (arry[i]=='羽毛球'){ $("#checkb3").attr("checked","true"); }else if (arry[i]=='游泳'){ $("#checkb4").attr("checked","true"); }else if (arry[i]=='跑步'){ $("#checkb5").attr("checked","true"); } } }); </script>