复选框问题,JS高手来帮忙噢..万分感谢啊
这个是用input框得到checkbox选项结果targetObj的代码
<html>
<head> <title> CheckBox Selected By Ctrl </title> </head>
<script>
function datanameEnable(checkObj) {
var checkObjList = document.getElementsByName( "xuanxiang ");
if(checkObj.checked){
document.myForm.targetObj.value+=checkObj.value+ ", ";
}
if(!checkObj.checked){
document.myForm.targetObj.value= " ";
for(i=0;i <checkObjList.length;i++){
if(checkObjList[i].checked){
document.myForm.targetObj.value+=checkObjList[i].value+ ", ";
}
}
}
}
</script>
<body>
<form name=myForm action= " " method=post>
<input type= "checkBox " name= "xuanxiang " value= "a " onclick= "datanameEnable(this); "> 记录1 <br/>
<input type= "checkBox " name= "xuanxiang " value= "b " onclick= "datanameEnable(this); "> 记录2 <br/>
<input type= "checkBox " name= "xuanxiang " value= "c " onclick= "datanameEnable(this); "> 记录3 <br/>
<input type= "text " name= "targetObj " value= " " >
</form>
</body>
</html>
那么我现在怎么从targetObj的value来选定复选框呢..
比如这个界面选定1,2得到的targetObj是 "a,b, "那么我现在知道targetObj是 "a,b, "怎么让界面上的复选框选中1,2选项呢.
------解决方案--------------------up
------解决方案--------------------我也在期待这个问题,UP
------解决方案--------------------function check(value){
var array = value.split( ", ");
for(i=0;i <document.myform.xuanxiang.length;i++){
for(j=0;j <array.length;j++){
if(array[j]==document.myform.xuanxiang[i].value)
document.myform.xuanxiang[i].checked=true;
}
}
}
差不多就是这样