varcheckedIds="";//翻页保存选中的id/***记录选择的元素*@return*/functionchangeIds(){varoneches=document.getElementsByName("ids");for(vari=0;iif(oneches[i].checked==true){ //避免重复添加(若存在元素时,不添加)if(!contains(checkedIds,oneches[i].value)){checkedIds+=oneches[i].value+",";//console.log(oneches[i].value);}}if(oneches[i].checked==false){//取消复选框时含有该id时将id从全局变量中去除if(contains(checkedIds,oneches[i].value)){checkedIds=checkedIds.replace((oneches[i].value+","),"");}}}}/****@return*/functiongetChecked(){if(checkedIds==""){return;}varoneches=document.getElementsByName("ids");for(vari=0;i//全局变量中含有id,则该复选框选中 if(contains(checkedIds,oneches[i].value)){oneches[i].checked="checked";//console.log(oneches[i].value);}}}/***判断数组是否存在元素*@paramobj*@paramele*@return*/functioncontains(obj,ele){//console.log(obj);//console.log(ele);if(obj==""){return;}/*若参数obj为字符串时,需要转换成数组*/vararr=obj.split(",");vari=arr.length;while(i--){if(arr[i]==ele){returntrue;}}returnfalse;}onclick="changeIds();getChecked();contains('1','2');"错误信息UncaughtTypeError:Failedtoexecute'contains'on'Node':parameter1isnotoftype'Node'.
开满天机
慕村225694
相关分类