Check box select all, reverse select and switch the selected value according to the value JS control check box

//1,控制全部选中不选中
$("input[name='"+checkName+"']").prop("checked", false);控制全部不选中
$("input[name='"+checkName+"']").prop("checked", true); 控制全部选中




//2,控制CheckBox某几个选中
	function selectCheckBox(checks,checkName){
		var checks=checks.split(",");       //------字符串以逗号分割
		var boxes = document.getElementsByName(checkName); //----根据name获取页面上的复选框

		//循环值,默认勾选处理
		for(i=0;i<boxes.length;i++){
			console.log("boxes[i].value==");	
			console.log(boxes[i].value);	
			for(j=0;j<=checks.length;j++){
				var isBreak="";
				if(boxes[i].value == checks[j]){
					boxes[i].checked = true;
					isBreak="yes";
				}else{
					boxes[i].checked = false;
				}
				if(isBreak=="yes"){//找value对应的tag到后结束循环
					break;
				}
			}

		}
	}
	

 

Guess you like

Origin blog.csdn.net/zhaofuqiangmycomm/article/details/104500514