리자

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

· 18년 전 · 2914
<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년 전 조회 3,013
18년 전 조회 2,334
18년 전 조회 2,517
18년 전 조회 3,066
18년 전 조회 3,154
18년 전 조회 4,321
18년 전 조회 6,300
18년 전 조회 2,253
18년 전 조회 2,367
18년 전 조회 2,077
18년 전 조회 1,817
18년 전 조회 2,824
18년 전 조회 1,859
18년 전 조회 1,733
18년 전 조회 4,924
18년 전 조회 1,970
18년 전 조회 2,014
18년 전 조회 2,024
18년 전 조회 2,148
18년 전 조회 3,807
18년 전 조회 1,828
18년 전 조회 1,702
18년 전 조회 1,529
18년 전 조회 2,035
18년 전 조회 2,072
18년 전 조회 3,844
18년 전 조회 2,175
18년 전 조회 3,316
18년 전 조회 4,931
18년 전 조회 3,060
18년 전 조회 8,232
18년 전 조회 4,253
18년 전 조회 2,942
18년 전 조회 1,704
18년 전 조회 2,815
18년 전 조회 5,230
18년 전 조회 5,399
18년 전 조회 2,277
18년 전 조회 4,533
18년 전 조회 4,281
18년 전 조회 4,327
18년 전 조회 2,454
18년 전 조회 4,385
18년 전 조회 2,366
18년 전 조회 3,471
18년 전 조회 5,113
18년 전 조회 2,135
18년 전 조회 3,593
18년 전 조회 1,822
18년 전 조회 2,915
18년 전 조회 1,862
18년 전 조회 2,906
18년 전 조회 2,738
18년 전 조회 1,754
18년 전 조회 1,693
18년 전 조회 1,943
18년 전 조회 2,438
18년 전 조회 2,225
18년 전 조회 2,567
18년 전 조회 5,087
18년 전 조회 1,994
18년 전 조회 1,429
18년 전 조회 1,554
18년 전 조회 1,525
18년 전 조회 1,248
18년 전 조회 1,251
18년 전 조회 1,593
18년 전 조회 1,545
18년 전 조회 2,540
18년 전 조회 1,415
18년 전 조회 1,793
18년 전 조회 2,271
18년 전 조회 1,456
18년 전 조회 3,020
18년 전 조회 1,464
18년 전 조회 1,830
18년 전 조회 1,678
18년 전 조회 1,627
18년 전 조회 1,417
18년 전 조회 1,237
18년 전 조회 1,851
18년 전 조회 1,283
18년 전 조회 3,804
18년 전 조회 1,904
18년 전 조회 1,985
18년 전 조회 1,303
18년 전 조회 2,052
18년 전 조회 1,282
18년 전 조회 1,358
18년 전 조회 1,195
18년 전 조회 1,181
18년 전 조회 1,268
18년 전 조회 2,769
18년 전 조회 1,731
18년 전 조회 1,816
18년 전 조회 1,369
18년 전 조회 2,038
18년 전 조회 1,679
18년 전 조회 1,664
18년 전 조회 1,883