1、HTML结构
<input name="test" type="checkbox" value="1" />item-1
<input name="test" type="checkbox" value="2" />item-2
<input name="test" type="checkbox" value="3" />item-3
<input name="test" type="checkbox" value="4" />item-4
<input name="test" type="checkbox" value="5" />item-5
<input type="text" id="idData"><input type="button" value="确定" onclick="save()">
2、javascript代码
function save(){
//val = "1,2,3,4,5"
var val = document.getElementById("idDate").value.split(",");
var boxes = document.getElementsByName("test");
for(i=0;i<boxes.length;i++){
for(j=0;j<val.length;j++){
if(boxes[i].value == val[j]){
boxes[i].checked = true;
break
}
}
}
}
|