Skip to content

Instantly share code, notes, and snippets.

@ayonliu
Created September 2, 2019 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayonliu/f1c3508e44863dbe4e2d001d307f0e8a to your computer and use it in GitHub Desktop.
Save ayonliu/f1c3508e44863dbe4e2d001d307f0e8a to your computer and use it in GitHub Desktop.
Check all checkbox by name
function opcheckboxed(objName, type){
var objNameList=document.getElementsByName(objName);
if(null!=objNameList){
for(var i=0;i<objNameList.length;i++){
if(objNameList[i].checked==true)
{
if(type != 'checkall') { // 非全选
objNameList[i].checked=false;
}
} else {
if(type != 'uncheckall') { // 非取消全选
objNameList[i].checked=true;
}
}
}
}
}
// example
opcheckboxed('oid[]', 'checkall');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment