삭제 행 동적 추가

3309 단어 삭제
// 
function addRow(tableName){
	if(window.ActiveXObject){
		addRowIE(tableName);
	}else{
		addRowFF(tableName);
	}
}
// 
function deleteRow(evt,tableName){
	if(window.ActiveXObject){
		deleteRowIE(tableName);
	}else{
		deleteRowFF(evt,tableName);
	}
}
//
function   get_Element(the_ele,the_tag){
	the_tag = the_tag.toLowerCase();
	if(the_ele.tagName.toLowerCase()==the_tag){
		return the_ele;
	}
	while(the_ele=the_ele.offsetParent){
		if(the_ele.tagName.toLowerCase()==the_tag){
			return the_ele;
		}
	}
	return(null);
}
function deleteRowIE(the_table){
	var the_cell;  
	the_cell=get_Element(event.srcElement,"td");  
	var index=the_cell.parentElement.rowIndex;
	if(the_cell==null)   return;   
	if(the_table.rows.length==1)   return;  
	var count=document.getElementById('inputTable').rows.length;
	// , 
	for(var i=index;i<count-1;i++){
		document.getElementById("inputTable").moveRow(i,i+1);
	}
	the_table.deleteRow(count-1);
}
function deleteRowFF(evt,the_table){
	var   the_cell;  
	the_cell=get_Element(evt.target,"td");
	var   index=the_cell.parentNode.rowIndex;
	// 
	the_table.deleteRow(index);
}
function addRowIE(tableName) 
{ 
	var newTr = document.getElementById(tableName).insertRow(); 
	//var newTdIndex = newTr.insertCell(); 
	var newTd0 = newTr.insertCell();
	var newTd1 = newTr.insertCell();
	var newTd2 = newTr.insertCell();
	newTd0.className="list_data_bg";
	newTd1.className="list_data_bg";
	newTd2.className="list_data_bg";
	newTd0.innerHTML = '<input type="hidden" name="stage_cd" value="0"/><span>noStage</span>'; 
	newTd1.innerHTML = '<input type="hidden" name="module_cd" value="0"/><span>noModule</span>'; 
	newTd2.innerHTML = '<a href="#" onclick="deleteRow(event,inputTable)"><IMG SRC="oams/images/standard/delete.gif" BORDER="0"></a>'; 
}
function addRowFF(tableName){
	var newTr = document.getElementById(tableName).insertRow(-1);
	//var newTdIndex = newTr.insertCell(); 
	var newTd0 = newTr.insertCell(-1);
	var newTd1 = newTr.insertCell(-1);
	var newTd2 = newTr.insertCell(-1);
	newTd0.setAttribute("class","list_data_bg");
	newTd1.setAttribute("class","list_data_bg");
	newTd2.setAttribute("class","list_data_bg");
	newTd0.innerHTML = '<input type="hidden" name="stage_cd" value="0"/><span>noStage</span>'; 
	newTd1.innerHTML = '<input type="hidden" name="module_cd" value="0"/><span>noModule</span>'; 
	newTd2.innerHTML = '<a href="#" onclick="deleteRow(event,inputTable)"><IMG SRC="oams/images/standard/delete.gif" BORDER="0"></a>'; 
}

좋은 웹페이지 즐겨찾기