日期:2014-05-16  浏览次数:20313 次

表格中删除指定行javascript操作
	function $(objId){ 
		return document.getElementById(objId); 
	} 
	function del_tbl(tblN,ckN){ 
		var ck = document.getElementsByName(ckN); 
    	var tab = $(tblN);
    	var existCk = false; 
		var rowIndex;
		if(ck){ 
			for(var i=0;i<ck.length;i++){ 
        		if(ck[i].checked){ 
        			existCk = true;
					rowIndex = ck[i].parentNode.parentNode.sectionRowIndex; 
        			tab.deleteRow(rowIndex); 
					i = -1; 
				} 
			} 
		}
		if (!existCk) {
			alert('请选择要删除的记录');
		}
	}

生成表格的javascript:

 function initTable(params){
        	var tableData = "<table id=\"decoderResourceTable\"  class=\"list-table\" align = \"center\"   style=\"margin:0;padding:0;\" cellspacing=\"1\" cellpadding=\"0\">";
        	tableData = tableData + "<tr>";
            tableData = tableData + "<td width=\"8%\" align=\"center\"><input type = \"checkbox\" id = \"checkAllId\" onclick = \"checkAll(this)\"/></td>";
        	tableData = tableData + "<td width=\"12%\" align=\"center\">编号</th>";
        	tableData = tableData + "<td width=\"34%\" align=\"center\">解码设备名称</td>";
        	tableData = tableData + "<td width=\"22%\" align=\"center\">设备类型</td>";
        	tableData = tableData + "<td width=\"24%\" align=\"center\">IP地址</td>";
        	tableData = tableData + "</tr>";
        	
        	for(var i=0; i<params.length; i++){
        		if (params[i] != ""){
        			var rowParams = params[i].split(";");
        			if(rowParams.length == 4){
        			    if( i%2 == 1 ){
        			       tableData = tableData + "<tr class=\"trEven\" align=\"center\" id=\"" + nCol + "\" onClick=\"\";>";
        			    } else {
        			       tableData = tableData + "<tr class=\"trOdd\" align=\"center\" id=\"" + nCol + "\" onClick=\"\";>";  
        			    }				
        				tableData = tableData + "<td class=\"list\"><input id = \"checkboxDecodesId\" type = \"checkbox\" name = \"checkboxRlDecodes\" /></td>";
        				tableData = tableData + "<td class=\"list\">" + nCol + "</td>";
        				tableData = tableData + "<td class=\"text-left\" class=\"list\">" + rowParams[1] + "</td>";
        				tableData = tableData + "<td class=\"text-left\" class=\"list\">" + rowParams[2] + "</td>";
        				tableData = tableData + "<td class=\"text-left\" class=\"list\">" + rowParams[3] + "</td>";
        				tableData = tableData + "<input type=\"hidden\" name=\"decodeResId\" value=\"" + rowParams[0] + "\"/>";
        				tableData = tableData + "<input type=\"hidden\" name=\"typeMtdsId\" value=\"" + rowParams[2] + "\"/>";
        				tableData = tableData + "</tr>";
        				nCol++;
        			}
        		}
        	}
        	tableData = tableData + "</table>";
        	old_Decoder = null;
        	
        	return tableData;
        }


全选所有checkBox的操作

function checkAll(chk){
   			var chkArray;
   			chkArray=document.getElementsByName("checkboxRlDecodes");
   			if(chk){
   			if(chkArray){
   				for(var i=0;i<chkArray.length;i++){
   					chkArray[i].checked=chk.checked;
   				}
  		 	}
  		 	}
		}