리자

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

· 2007-05-08 (화) 09:37:31 · 3936
<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건
+
제목 글쓴이 날짜 조회
08-04-03 조회 2,794
08-04-02 조회 2,993
08-04-02 조회 2,866
08-04-02 조회 3,183
08-04-02 조회 3,141
08-04-02 조회 3,168
08-04-02 조회 3,113
08-04-02 조회 2,817
08-04-02 조회 2,814
08-04-02 조회 2,922
08-04-02 조회 3,223
08-04-02 조회 3,109
08-04-02 조회 2,893
08-04-02 조회 3,033
08-04-02 조회 2,700
08-04-02 조회 2,962
08-04-02 조회 3,282
08-04-02 조회 4,080
08-04-02 조회 3,273
08-03-31 조회 2,573
08-03-31 조회 3,137
08-03-31 조회 3,640
08-03-29 조회 2,765
08-03-28 조회 3,471
08-03-28 조회 2,969
08-03-28 조회 2,638
08-03-27 조회 2,469
08-03-26 조회 3,374
08-03-26 조회 4,334
08-03-25 조회 3,803
08-03-25 조회 2,816
08-03-25 조회 4,133
08-03-25 조회 3,640
08-03-25 조회 4,060
08-03-25 조회 4,087
08-03-25 조회 3,747
08-03-25 조회 3,647
08-03-25 조회 2,902
08-03-25 조회 3,656
08-03-25 조회 5,355
08-03-21 조회 3,018
08-03-19 조회 5,181
08-03-18 조회 3,037
08-03-16 조회 3,001
08-03-14 조회 3,320
08-03-13 조회 3,712
08-03-13 조회 2,693
08-03-11 조회 3,017
08-03-11 조회 3,568
08-03-11 조회 3,060
08-03-11 조회 3,022
08-03-11 조회 2,814
08-03-11 조회 2,657
08-03-11 조회 2,599
08-03-11 조회 2,410
08-03-11 조회 2,420
08-03-11 조회 2,471
08-03-11 조회 2,452
08-03-11 조회 2,857
08-03-11 조회 2,928
08-03-08 조회 3,153
08-03-07 조회 4,268
08-03-07 조회 3,375
08-03-07 조회 3,033
08-03-06 조회 3,381
08-03-06 조회 3,127
08-03-06 조회 4,812
08-03-05 조회 2,748
08-03-04 조회 2,892
08-03-04 조회 2,593
08-03-04 조회 3,456
08-03-03 조회 4,430
08-02-28 조회 3,524
08-02-27 조회 3,012
08-02-22 조회 4,332
08-02-22 조회 5,706
08-02-22 조회 2,970
08-02-21 조회 4,648
08-02-21 조회 2,876
08-02-21 조회 4,872
08-02-21 조회 7,151
08-02-21 조회 2,663
08-02-21 조회 3,432
08-02-20 조회 3,101
08-02-19 조회 2,768
08-02-19 조회 3,624
08-02-19 조회 3,837
08-02-15 조회 2,802
08-02-15 조회 3,985
08-02-14 조회 4,494
08-02-14 조회 2,690
08-02-12 조회 3,141
08-02-11 조회 5,143
08-02-09 조회 5,885
08-02-09 조회 3,075
08-02-08 조회 2,930
08-02-05 조회 3,943
08-02-04 조회 3,144
08-02-03 조회 5,433
08-02-03 조회 2,842