要求是从服务器取一个字段,比如A,然后将页面中所有叫CITYA的选项全选.如果传的是B,则选所有的CITYB.本人JS知识有限,请有心人提供下JS代码和调用处的代码.谢谢.
------解决方案--------------------
假设:
<input type= "checkbox " name= "city " value= "cityA "> CITYA
<input type= "checkbox " name= "city " value= "cityB "> CITYB
首先是遍历所有CheckBox对象:
var boxobj = document.getElementsByName( "city ");
然后根据它的值与目标值进行比较:
for(var i=0;i <boxobj.length;i++){
//符合条件的就选上:
if(boxobj[i].value == "cityA "){
boxobj[i].checked = true;
}
}