리자

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

· 2007-05-08 (화) 09:37:31 · 3869
<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,341
07-05-09 조회 3,423
07-05-09 조회 5,364
07-05-09 조회 3,445
07-05-09 조회 4,524
07-05-09 조회 6,067
07-05-08 조회 3,130
07-05-08 조회 4,501
07-05-08 조회 2,825
07-05-08 조회 3,870
07-05-07 조회 2,868
07-05-05 조회 3,906
07-05-04 조회 3,730
07-05-04 조회 2,723
07-05-04 조회 2,661
07-05-04 조회 2,890
07-05-04 조회 3,467
07-05-04 조회 3,215
07-05-04 조회 3,552
07-05-04 조회 6,155
07-05-04 조회 2,931
07-05-04 조회 2,362
07-05-04 조회 2,473
07-05-04 조회 2,447
07-05-04 조회 2,192
07-05-04 조회 2,150
07-05-04 조회 2,499
07-05-04 조회 2,484
07-05-04 조회 3,444
07-05-04 조회 2,361
07-05-04 조회 2,752
07-05-04 조회 3,258
07-05-04 조회 2,391
07-05-04 조회 3,982
07-05-04 조회 2,446
07-05-04 조회 2,827
07-05-04 조회 2,654
07-05-04 조회 2,560
07-05-04 조회 2,391
07-05-04 조회 2,225
07-05-04 조회 2,844
07-05-04 조회 2,236
07-05-04 조회 4,819
07-05-04 조회 2,857
07-05-02 조회 2,949
07-05-02 조회 2,280
07-05-02 조회 3,001
07-05-02 조회 2,233
07-05-02 조회 2,298
07-05-02 조회 2,137
07-05-02 조회 2,104
07-05-02 조회 2,190
07-05-02 조회 3,699
07-05-01 조회 2,667
07-05-01 조회 2,771
07-05-01 조회 2,334
07-05-01 조회 3,010
07-05-01 조회 2,670
07-05-01 조회 2,639
07-05-01 조회 2,852
07-05-01 조회 2,130
07-05-01 조회 2,569
07-05-01 조회 3,435
07-05-01 조회 2,292
07-05-01 조회 2,473
07-05-01 조회 2,711
07-05-01 조회 2,316
07-05-01 조회 2,118
07-05-01 조회 2,322
07-05-01 조회 2,668
07-05-01 조회 2,791
07-05-01 조회 2,718
07-05-01 조회 2,330
07-04-30 조회 9,801
07-04-30 조회 3,118
07-04-30 조회 2,670
07-04-30 조회 2,636
07-04-30 조회 2,977
07-04-30 조회 3,050
07-04-30 조회 2,400
07-04-30 조회 2,134
07-04-30 조회 3,950
07-04-30 조회 4,324
07-04-30 조회 3,379
07-04-30 조회 2,783
07-04-30 조회 2,606
07-04-30 조회 2,034
07-04-28 조회 2,951
07-04-28 조회 6,460
07-04-27 조회 4,051
07-04-27 조회 3,396
07-04-27 조회 4,298
07-04-26 조회 3,706
07-04-26 조회 3,415
07-04-26 조회 5,726
07-04-26 조회 4,705
07-04-25 조회 4,709
07-04-25 조회 5,240
07-04-25 조회 3,140
07-04-22 조회 2,912