리자

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

· 2007-05-08 (화) 09:37:31 · 3941
<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,187건
+
제목 글쓴이 날짜 조회
07-05-09 조회 3,519
07-05-09 조회 5,462
07-05-09 조회 3,549
07-05-09 조회 4,604
07-05-09 조회 6,155
07-05-08 조회 3,208
07-05-08 조회 4,570
07-05-08 조회 2,900
07-05-08 조회 3,942
07-05-07 조회 2,954
07-05-05 조회 3,991
07-05-04 조회 3,816
07-05-04 조회 2,813
07-05-04 조회 2,753
07-05-04 조회 2,973
07-05-04 조회 3,550
07-05-04 조회 3,310
07-05-04 조회 3,645
07-05-04 조회 6,242
07-05-04 조회 3,009
07-05-04 조회 2,433
07-05-04 조회 2,538
07-05-04 조회 2,511
07-05-04 조회 2,255
07-05-04 조회 2,212
07-05-04 조회 2,569
07-05-04 조회 2,542
07-05-04 조회 3,500
07-05-04 조회 2,414
07-05-04 조회 2,803
07-05-04 조회 3,321
07-05-04 조회 2,453
07-05-04 조회 4,040
07-05-04 조회 2,506
07-05-04 조회 2,886
07-05-04 조회 2,704
07-05-04 조회 2,610
07-05-04 조회 2,442
07-05-04 조회 2,286
07-05-04 조회 2,907
07-05-04 조회 2,293
07-05-04 조회 4,880
07-05-04 조회 2,933
07-05-02 조회 3,025
07-05-02 조회 2,337
07-05-02 조회 3,058
07-05-02 조회 2,288
07-05-02 조회 2,350
07-05-02 조회 2,193
07-05-02 조회 2,158
07-05-02 조회 2,249
07-05-02 조회 3,776
07-05-01 조회 2,732
07-05-01 조회 2,834
07-05-01 조회 2,398
07-05-01 조회 3,078
07-05-01 조회 2,728
07-05-01 조회 2,698
07-05-01 조회 2,916
07-05-01 조회 2,186
07-05-01 조회 2,626
07-05-01 조회 3,498
07-05-01 조회 2,352
07-05-01 조회 2,532
07-05-01 조회 2,764
07-05-01 조회 2,368
07-05-01 조회 2,172
07-05-01 조회 2,381
07-05-01 조회 2,728
07-05-01 조회 2,849
07-05-01 조회 2,784
07-05-01 조회 2,403
07-04-30 조회 9,893
07-04-30 조회 3,210
07-04-30 조회 2,741
07-04-30 조회 2,705
07-04-30 조회 3,044
07-04-30 조회 3,114
07-04-30 조회 2,470
07-04-30 조회 2,212
07-04-30 조회 4,027
07-04-30 조회 4,418
07-04-30 조회 3,465
07-04-30 조회 2,869
07-04-30 조회 2,683
07-04-30 조회 2,116
07-04-28 조회 3,054
07-04-28 조회 6,591
07-04-27 조회 4,161
07-04-27 조회 3,498
07-04-27 조회 4,394
07-04-26 조회 3,800
07-04-26 조회 3,500
07-04-26 조회 5,812
07-04-26 조회 4,808
07-04-25 조회 4,813
07-04-25 조회 5,348
07-04-25 조회 3,233
07-04-22 조회 3,001
07-04-22 조회 3,003