리자

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

· 2007-05-08 (화) 09:37:31 · 3871
<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에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
07-05-10 조회 5,344
07-05-09 조회 3,425
07-05-09 조회 5,368
07-05-09 조회 3,451
07-05-09 조회 4,526
07-05-09 조회 6,068
07-05-08 조회 3,131
07-05-08 조회 4,505
07-05-08 조회 2,826
07-05-08 조회 3,872
07-05-07 조회 2,869
07-05-05 조회 3,908
07-05-04 조회 3,737
07-05-04 조회 2,724
07-05-04 조회 2,664
07-05-04 조회 2,890
07-05-04 조회 3,470
07-05-04 조회 3,217
07-05-04 조회 3,556
07-05-04 조회 6,159
07-05-04 조회 2,935
07-05-04 조회 2,368
07-05-04 조회 2,478
07-05-04 조회 2,450
07-05-04 조회 2,193
07-05-04 조회 2,151
07-05-04 조회 2,502
07-05-04 조회 2,489
07-05-04 조회 3,447
07-05-04 조회 2,366
07-05-04 조회 2,758
07-05-04 조회 3,258
07-05-04 조회 2,393
07-05-04 조회 3,984
07-05-04 조회 2,446
07-05-04 조회 2,829
07-05-04 조회 2,657
07-05-04 조회 2,564
07-05-04 조회 2,396
07-05-04 조회 2,226
07-05-04 조회 2,848
07-05-04 조회 2,236
07-05-04 조회 4,822
07-05-04 조회 2,858
07-05-02 조회 2,951
07-05-02 조회 2,283
07-05-02 조회 3,004
07-05-02 조회 2,235
07-05-02 조회 2,300
07-05-02 조회 2,137
07-05-02 조회 2,106
07-05-02 조회 2,193
07-05-02 조회 3,699
07-05-01 조회 2,670
07-05-01 조회 2,774
07-05-01 조회 2,336
07-05-01 조회 3,013
07-05-01 조회 2,675
07-05-01 조회 2,643
07-05-01 조회 2,855
07-05-01 조회 2,131
07-05-01 조회 2,570
07-05-01 조회 3,437
07-05-01 조회 2,294
07-05-01 조회 2,476
07-05-01 조회 2,712
07-05-01 조회 2,321
07-05-01 조회 2,121
07-05-01 조회 2,326
07-05-01 조회 2,672
07-05-01 조회 2,796
07-05-01 조회 2,719
07-05-01 조회 2,331
07-04-30 조회 9,804
07-04-30 조회 3,122
07-04-30 조회 2,674
07-04-30 조회 2,642
07-04-30 조회 2,977
07-04-30 조회 3,053
07-04-30 조회 2,406
07-04-30 조회 2,139
07-04-30 조회 3,952
07-04-30 조회 4,327
07-04-30 조회 3,381
07-04-30 조회 2,789
07-04-30 조회 2,613
07-04-30 조회 2,043
07-04-28 조회 2,958
07-04-28 조회 6,463
07-04-27 조회 4,054
07-04-27 조회 3,396
07-04-27 조회 4,302
07-04-26 조회 3,708
07-04-26 조회 3,419
07-04-26 조회 5,727
07-04-26 조회 4,709
07-04-25 조회 4,711
07-04-25 조회 5,240
07-04-25 조회 3,143
07-04-22 조회 2,916