본문 바로가기

Web/JSP

jsp 행 동적 추가

<html>

<head>

<script language="javascript">

//행추가 
function addRow(){

var Table = document.getElementById('table_id'); 
var newRow = questTable.insertRow();  //TR추가
var newCell1 = newRow.insertCell();       //TD추가
var newCell2 = newRow.insertCell();       //TD추가

 

newCell1.className="aa";                         //TD스타일 설정
newCell2.className="bb";                         //TD스타일 설정

 

newCell1.innerHTML = "<input name='이름' type='text' class='input스타일속성' value='값' >";

newCell1.innerHTML = "<input name='이름2' type='text' class='input스타일속성2' value='값2' >"; 

}

 

//행삭제
function addRow(){

//마지막 행부터 지우기

var io = table_id.rows.length - 1; //마지막행 인덱스 찾기
document.getElementById('table_id').deleteRow(io);

}

</script>

<body>

<form name="form">

<table id="table_id">

<tr>

<td class="aa">

<input name='이름' type='text' class='input스타일속성' value='값' >

</td>

<td class="bb">

<input name='이름' type='text' class='input스타일속성' value='값' >

</td>

</tr>

</table>

</form>

</body>

</html>

 

[출처] JSP 행추가/삭제|작성자 아인이편