리자

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

· 18년 전 · 2791
<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,881
18년 전 조회 2,200
18년 전 조회 2,382
18년 전 조회 2,932
18년 전 조회 3,018
18년 전 조회 4,188
18년 전 조회 6,176
18년 전 조회 2,118
18년 전 조회 2,246
18년 전 조회 1,946
18년 전 조회 1,701
18년 전 조회 2,688
18년 전 조회 1,735
18년 전 조회 1,609
18년 전 조회 4,792
18년 전 조회 1,834
18년 전 조회 1,891
18년 전 조회 1,897
18년 전 조회 2,020
18년 전 조회 3,682
18년 전 조회 1,700
18년 전 조회 1,578
18년 전 조회 1,407
18년 전 조회 1,913
18년 전 조회 1,949
18년 전 조회 3,712
18년 전 조회 2,031
18년 전 조회 3,171
18년 전 조회 4,802
18년 전 조회 2,930
18년 전 조회 8,098
18년 전 조회 4,106
18년 전 조회 2,804
18년 전 조회 1,579
18년 전 조회 2,683
18년 전 조회 5,092
18년 전 조회 5,274
18년 전 조회 2,147
18년 전 조회 4,404
18년 전 조회 4,151
18년 전 조회 4,210
18년 전 조회 2,330
18년 전 조회 4,245
18년 전 조회 2,239
18년 전 조회 3,337
18년 전 조회 4,973
18년 전 조회 2,001
18년 전 조회 3,466
18년 전 조회 1,694
18년 전 조회 2,792
18년 전 조회 1,729
18년 전 조회 2,775
18년 전 조회 2,610
18년 전 조회 1,611
18년 전 조회 1,553
18년 전 조회 1,800
18년 전 조회 2,306
18년 전 조회 2,078
18년 전 조회 2,427
18년 전 조회 4,958
18년 전 조회 1,870
18년 전 조회 1,307
18년 전 조회 1,429
18년 전 조회 1,395
18년 전 조회 1,132
18년 전 조회 1,128
18년 전 조회 1,463
18년 전 조회 1,416
18년 전 조회 2,408
18년 전 조회 1,286
18년 전 조회 1,668
18년 전 조회 2,135
18년 전 조회 1,330
18년 전 조회 2,880
18년 전 조회 1,331
18년 전 조회 1,708
18년 전 조회 1,549
18년 전 조회 1,506
18년 전 조회 1,285
18년 전 조회 1,124
18년 전 조회 1,719
18년 전 조회 1,152
18년 전 조회 3,668
18년 전 조회 1,768
18년 전 조회 1,844
18년 전 조회 1,166
18년 전 조회 1,907
18년 전 조회 1,145
18년 전 조회 1,217
18년 전 조회 1,070
18년 전 조회 1,048
18년 전 조회 1,137
18년 전 조회 2,630
18년 전 조회 1,596
18년 전 조회 1,679
18년 전 조회 1,245
18년 전 조회 1,911
18년 전 조회 1,562
18년 전 조회 1,531
18년 전 조회 1,748