리자

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

· 18년 전 · 2765
<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에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
18년 전 조회 2,851
18년 전 조회 2,164
18년 전 조회 2,351
18년 전 조회 2,895
18년 전 조회 2,990
18년 전 조회 4,164
18년 전 조회 6,142
18년 전 조회 2,081
18년 전 조회 2,216
18년 전 조회 1,923
18년 전 조회 1,678
18년 전 조회 2,658
18년 전 조회 1,709
18년 전 조회 1,586
18년 전 조회 4,766
18년 전 조회 1,813
18년 전 조회 1,869
18년 전 조회 1,877
18년 전 조회 1,998
18년 전 조회 3,652
18년 전 조회 1,680
18년 전 조회 1,556
18년 전 조회 1,384
18년 전 조회 1,884
18년 전 조회 1,932
18년 전 조회 3,675
18년 전 조회 2,004
18년 전 조회 3,146
18년 전 조회 4,767
18년 전 조회 2,903
18년 전 조회 8,077
18년 전 조회 4,086
18년 전 조회 2,773
18년 전 조회 1,549
18년 전 조회 2,653
18년 전 조회 5,067
18년 전 조회 5,243
18년 전 조회 2,123
18년 전 조회 4,375
18년 전 조회 4,124
18년 전 조회 4,176
18년 전 조회 2,295
18년 전 조회 4,222
18년 전 조회 2,201
18년 전 조회 3,310
18년 전 조회 4,945
18년 전 조회 1,978
18년 전 조회 3,446
18년 전 조회 1,668
18년 전 조회 2,766
18년 전 조회 1,700
18년 전 조회 2,744
18년 전 조회 2,579
18년 전 조회 1,584
18년 전 조회 1,520
18년 전 조회 1,767
18년 전 조회 2,269
18년 전 조회 2,048
18년 전 조회 2,405
18년 전 조회 4,938
18년 전 조회 1,848
18년 전 조회 1,284
18년 전 조회 1,408
18년 전 조회 1,368
18년 전 조회 1,110
18년 전 조회 1,102
18년 전 조회 1,439
18년 전 조회 1,393
18년 전 조회 2,387
18년 전 조회 1,257
18년 전 조회 1,637
18년 전 조회 2,111
18년 전 조회 1,305
18년 전 조회 2,854
18년 전 조회 1,304
18년 전 조회 1,681
18년 전 조회 1,532
18년 전 조회 1,482
18년 전 조회 1,261
18년 전 조회 1,103
18년 전 조회 1,693
18년 전 조회 1,131
18년 전 조회 3,643
18년 전 조회 1,740
18년 전 조회 1,819
18년 전 조회 1,143
18년 전 조회 1,883
18년 전 조회 1,131
18년 전 조회 1,198
18년 전 조회 1,050
18년 전 조회 1,027
18년 전 조회 1,121
18년 전 조회 2,606
18년 전 조회 1,574
18년 전 조회 1,660
18년 전 조회 1,226
18년 전 조회 1,892
18년 전 조회 1,543
18년 전 조회 1,507
18년 전 조회 1,733