리자

JS 이용해서 동적으로 테이블 생성

· 18년 전 · 2916
<script>
    function erase(o)
    {
        alert(document.getElementById(o));
        document.getElementById(o).removeChild(document.getElementById(o).getElementsByTagName('tr')[0]);
    }

    function make()
    {
        alert("우하하");
        var tbl     = document.getElementById("tbl");
        var tblBody = document.getElementById("tblBody");

        // creating all cells
        for (var j = 0; j < 2; j++) {
            // creates a table row
            var row = document.createElement("tr");

            for (var i = 0; i < 2; i++) {
                // Create a <td> element and a text node, make the text
                // node the contents of the <td>, and put the <td> at
                // the end of the table row
                var cell = document.createElement("td");
                var cellText = document.createTextNode("cell is row "+j+", column "+i);
                cell.appendChild(cellText);
                row.appendChild(cell);
            }

            // add the row to the end of the table body
            tblBody.appendChild(row);
        }
        tbl.setAttribute("border", "2");
    }
</script>

<input type="button" value="start" onclick="make()">
<input type="button" value="delete" onclick="erase('tblBody');">

<table id="tbl">
    <tbody id="tblBody">


    </tbody>
</table>
 
꼭 tbody 태그를 넣어야 한다는거 유의!!
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
18년 전 조회 3,017
18년 전 조회 2,335
18년 전 조회 2,519
18년 전 조회 3,070
18년 전 조회 3,156
18년 전 조회 4,323
18년 전 조회 6,300
18년 전 조회 2,259
18년 전 조회 2,372
18년 전 조회 2,079
18년 전 조회 1,818
18년 전 조회 2,824
18년 전 조회 1,863
18년 전 조회 1,734
18년 전 조회 4,928
18년 전 조회 1,973
18년 전 조회 2,014
18년 전 조회 2,026
18년 전 조회 2,150
18년 전 조회 3,810
18년 전 조회 1,828
18년 전 조회 1,703
18년 전 조회 1,531
18년 전 조회 2,036
18년 전 조회 2,073
18년 전 조회 3,847
18년 전 조회 2,177
18년 전 조회 3,318
18년 전 조회 4,934
18년 전 조회 3,063
18년 전 조회 8,233
18년 전 조회 4,253
18년 전 조회 2,945
18년 전 조회 1,709
18년 전 조회 2,818
18년 전 조회 5,231
18년 전 조회 5,404
18년 전 조회 2,279
18년 전 조회 4,535
18년 전 조회 4,284
18년 전 조회 4,327
18년 전 조회 2,454
18년 전 조회 4,385
18년 전 조회 2,368
18년 전 조회 3,472
18년 전 조회 5,117
18년 전 조회 2,135
18년 전 조회 3,594
18년 전 조회 1,824
18년 전 조회 2,917
18년 전 조회 1,868
18년 전 조회 2,911
18년 전 조회 2,740
18년 전 조회 1,759
18년 전 조회 1,695
18년 전 조회 1,943
18년 전 조회 2,442
18년 전 조회 2,228
18년 전 조회 2,570
18년 전 조회 5,092
18년 전 조회 1,998
18년 전 조회 1,431
18년 전 조회 1,556
18년 전 조회 1,525
18년 전 조회 1,251
18년 전 조회 1,251
18년 전 조회 1,596
18년 전 조회 1,546
18년 전 조회 2,542
18년 전 조회 1,418
18년 전 조회 1,795
18년 전 조회 2,273
18년 전 조회 1,459
18년 전 조회 3,024
18년 전 조회 1,464
18년 전 조회 1,831
18년 전 조회 1,680
18년 전 조회 1,629
18년 전 조회 1,419
18년 전 조회 1,239
18년 전 조회 1,854
18년 전 조회 1,287
18년 전 조회 3,808
18년 전 조회 1,907
18년 전 조회 1,985
18년 전 조회 1,304
18년 전 조회 2,052
18년 전 조회 1,285
18년 전 조회 1,359
18년 전 조회 1,199
18년 전 조회 1,183
18년 전 조회 1,269
18년 전 조회 2,769
18년 전 조회 1,731
18년 전 조회 1,817
18년 전 조회 1,371
18년 전 조회 2,040
18년 전 조회 1,681
18년 전 조회 1,667
18년 전 조회 1,885