리자

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

· 18년 전 · 2778
<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,870
18년 전 조회 2,191
18년 전 조회 2,371
18년 전 조회 2,920
18년 전 조회 3,008
18년 전 조회 4,183
18년 전 조회 6,165
18년 전 조회 2,108
18년 전 조회 2,235
18년 전 조회 1,941
18년 전 조회 1,694
18년 전 조회 2,676
18년 전 조회 1,725
18년 전 조회 1,603
18년 전 조회 4,784
18년 전 조회 1,829
18년 전 조회 1,884
18년 전 조회 1,891
18년 전 조회 2,008
18년 전 조회 3,677
18년 전 조회 1,689
18년 전 조회 1,572
18년 전 조회 1,403
18년 전 조회 1,904
18년 전 조회 1,944
18년 전 조회 3,702
18년 전 조회 2,025
18년 전 조회 3,162
18년 전 조회 4,792
18년 전 조회 2,922
18년 전 조회 8,089
18년 전 조회 4,101
18년 전 조회 2,796
18년 전 조회 1,573
18년 전 조회 2,674
18년 전 조회 5,085
18년 전 조회 5,264
18년 전 조회 2,138
18년 전 조회 4,394
18년 전 조회 4,145
18년 전 조회 4,202
18년 전 조회 2,319
18년 전 조회 4,239
18년 전 조회 2,226
18년 전 조회 3,330
18년 전 조회 4,964
18년 전 조회 1,994
18년 전 조회 3,460
18년 전 조회 1,684
18년 전 조회 2,779
18년 전 조회 1,720
18년 전 조회 2,762
18년 전 조회 2,600
18년 전 조회 1,605
18년 전 조회 1,543
18년 전 조회 1,792
18년 전 조회 2,295
18년 전 조회 2,068
18년 전 조회 2,420
18년 전 조회 4,953
18년 전 조회 1,865
18년 전 조회 1,299
18년 전 조회 1,419
18년 전 조회 1,386
18년 전 조회 1,125
18년 전 조회 1,119
18년 전 조회 1,457
18년 전 조회 1,410
18년 전 조회 2,399
18년 전 조회 1,277
18년 전 조회 1,658
18년 전 조회 2,128
18년 전 조회 1,327
18년 전 조회 2,872
18년 전 조회 1,319
18년 전 조회 1,699
18년 전 조회 1,545
18년 전 조회 1,498
18년 전 조회 1,277
18년 전 조회 1,119
18년 전 조회 1,712
18년 전 조회 1,149
18년 전 조회 3,659
18년 전 조회 1,759
18년 전 조회 1,837
18년 전 조회 1,160
18년 전 조회 1,903
18년 전 조회 1,141
18년 전 조회 1,214
18년 전 조회 1,062
18년 전 조회 1,041
18년 전 조회 1,132
18년 전 조회 2,622
18년 전 조회 1,591
18년 전 조회 1,674
18년 전 조회 1,237
18년 전 조회 1,906
18년 전 조회 1,558
18년 전 조회 1,524
18년 전 조회 1,744