테이블 deleteRow() 메서드
예시
테이블의 첫 번째 행 삭제:
document.getElementById("myTable").deleteRow(0);
정의 및 사용
deleteRow() 메서드는 테이블에서 지정된 인덱스의 행을 제거합니다.
팁: insertRow() 를 사용 하여 새 행을 만들고 삽입하십시오.
브라우저 지원
Method | |||||
---|---|---|---|---|---|
deleteRow() | Yes | Yes | Yes | Yes | Yes |
통사론
tableObject.deleteRow(index)
매개변수 값
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. An integer that specifies the position of the row to delete (starts at 0). The value of 0 results in that the first row will be deleted. The value of -1 can also be used; which result in that the last row will be deleted. This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari. If this parameter is omitted, deleteRow() removes the last row in IE and the first row in Chrome and Safari. |
기술적 세부 사항
반환 값: | 반환 값 없음 |
---|
더 많은 예
예시
클릭한 행 삭제:
function deleteRow(r) {
var i = r.parentNode.parentNode.rowIndex;
document.getElementById("myTable").deleteRow(i);
}
예시
행 생성 및 삭제:
function myCreateFunction() {
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteRow(0);
}
관련 페이지
HTML 참조: HTML <tr> 태그
❮ 테이블 개체