리자

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

· 2007-05-08 (화) 09:37:31 · 3900
<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,390
07-05-09 조회 3,469
07-05-09 조회 5,417
07-05-09 조회 3,507
07-05-09 조회 4,566
07-05-09 조회 6,112
07-05-08 조회 3,167
07-05-08 조회 4,531
07-05-08 조회 2,859
07-05-08 조회 3,901
07-05-07 조회 2,903
07-05-05 조회 3,948
07-05-04 조회 3,784
07-05-04 조회 2,774
07-05-04 조회 2,705
07-05-04 조회 2,915
07-05-04 조회 3,500
07-05-04 조회 3,263
07-05-04 조회 3,594
07-05-04 조회 6,200
07-05-04 조회 2,972
07-05-04 조회 2,403
07-05-04 조회 2,509
07-05-04 조회 2,475
07-05-04 조회 2,219
07-05-04 조회 2,176
07-05-04 조회 2,534
07-05-04 조회 2,514
07-05-04 조회 3,476
07-05-04 조회 2,387
07-05-04 조회 2,776
07-05-04 조회 3,285
07-05-04 조회 2,426
07-05-04 조회 4,012
07-05-04 조회 2,473
07-05-04 조회 2,852
07-05-04 조회 2,678
07-05-04 조회 2,589
07-05-04 조회 2,419
07-05-04 조회 2,256
07-05-04 조회 2,874
07-05-04 조회 2,262
07-05-04 조회 4,850
07-05-04 조회 2,886
07-05-02 조회 2,983
07-05-02 조회 2,310
07-05-02 조회 3,037
07-05-02 조회 2,265
07-05-02 조회 2,325
07-05-02 조회 2,164
07-05-02 조회 2,130
07-05-02 조회 2,219
07-05-02 조회 3,738
07-05-01 조회 2,703
07-05-01 조회 2,806
07-05-01 조회 2,368
07-05-01 조회 3,046
07-05-01 조회 2,704
07-05-01 조회 2,671
07-05-01 조회 2,886
07-05-01 조회 2,153
07-05-01 조회 2,601
07-05-01 조회 3,473
07-05-01 조회 2,330
07-05-01 조회 2,501
07-05-01 조회 2,735
07-05-01 조회 2,341
07-05-01 조회 2,148
07-05-01 조회 2,352
07-05-01 조회 2,697
07-05-01 조회 2,819
07-05-01 조회 2,748
07-05-01 조회 2,361
07-04-30 조회 9,839
07-04-30 조회 3,155
07-04-30 조회 2,707
07-04-30 조회 2,678
07-04-30 조회 3,017
07-04-30 조회 3,085
07-04-30 조회 2,430
07-04-30 조회 2,170
07-04-30 조회 3,990
07-04-30 조회 4,379
07-04-30 조회 3,423
07-04-30 조회 2,827
07-04-30 조회 2,645
07-04-30 조회 2,081
07-04-28 조회 3,007
07-04-28 조회 6,523
07-04-27 조회 4,114
07-04-27 조회 3,440
07-04-27 조회 4,342
07-04-26 조회 3,752
07-04-26 조회 3,460
07-04-26 조회 5,763
07-04-26 조회 4,756
07-04-25 조회 4,767
07-04-25 조회 5,303
07-04-25 조회 3,182
07-04-22 조회 2,953