리자

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

· 2007-05-08 (화) 09:37:31 · 3829
<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건
+
제목 글쓴이 날짜 조회
08-04-17 조회 4,317
08-03-14 조회 3,204
08-03-08 조회 3,027
08-03-06 조회 2,997
08-03-03 조회 4,285
08-02-20 조회 2,975
08-02-15 조회 3,886
08-02-11 조회 5,044
08-02-09 조회 5,763
08-02-05 조회 3,816
08-01-14 조회 6,628
08-01-11 조회 7,060
08-01-04 조회 1.1만
07-12-10 조회 4,968
07-12-10 조회 3,834
07-12-04 조회 3,373
07-11-29 조회 3,547
07-11-27 조회 3,904
07-11-23 조회 4,503
07-11-23 조회 4,235
07-11-13 조회 4,362
07-10-19 조회 4,822
07-10-17 조회 5,875
07-10-03 조회 4,959
07-10-02 조회 8,797
07-10-02 조회 4,455
07-09-09 조회 3,422
07-07-29 조회 4,310
07-07-28 조회 4,536
07-07-26 조회 4,440
07-06-19 조회 1.1만
07-06-17 조회 3,607
07-06-15 조회 4,104
07-05-31 조회 3,163
07-05-09 조회 5,317
07-05-04 조회 3,163
07-05-04 조회 3,511
07-04-28 조회 6,408
07-04-26 조회 4,654
07-04-14 조회 5,298
07-04-13 조회 3,714
07-04-12 조회 5,909
07-03-27 조회 3,849
07-03-19 조회 3,547
07-03-13 조회 4,621
07-03-07 조회 4,771
07-03-07 조회 3,283
07-02-25 조회 3,639
07-02-21 조회 4,532
07-02-18 조회 5,049
07-02-12 조회 3,395
07-02-02 조회 4,511
07-01-28 조회 6,121
07-01-27 조회 5,631
07-01-25 조회 3,995
07-01-21 조회 4,629
07-01-19 조회 6,571
07-01-19 조회 8,030
07-01-13 조회 3,487
07-01-09 조회 5,127
06-12-27 조회 3,530
06-11-24 조회 3,646
06-11-18 조회 4,166
06-10-17 조회 5,485
06-10-01 조회 4,409
06-09-26 조회 4,291
06-09-25 조회 4,609
06-09-25 조회 4,325
06-09-22 조회 4,852
06-09-22 조회 3,624
06-09-22 조회 4,454
06-09-13 조회 5,284
06-08-27 조회 4,886
06-08-26 조회 6,266
06-08-26 조회 5,570
06-08-23 조회 5,066
06-07-28 조회 7,166
06-07-24 조회 4,623
06-07-23 조회 5,408
06-07-21 조회 5,165
06-07-19 조회 3,048
06-07-19 조회 2,958
06-07-11 조회 3,618
06-07-11 조회 3,910
06-07-11 조회 4,482
06-07-11 조회 4,945
06-07-11 조회 3,569
06-07-11 조회 9,191
06-07-11 조회 4,053
06-07-11 조회 3,283
06-07-11 조회 3,331
06-07-11 조회 3,263
06-07-11 조회 3,066
06-07-07 조회 4,107
06-06-25 조회 4,456
06-06-15 조회 4,450
06-06-14 조회 4,940
06-06-11 조회 3,523
06-06-10 조회 3,904
06-06-09 조회 3,489