리자

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

· 18년 전 · 2766
<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,852
18년 전 조회 2,166
18년 전 조회 2,355
18년 전 조회 2,901
18년 전 조회 2,994
18년 전 조회 4,166
18년 전 조회 6,144
18년 전 조회 2,082
18년 전 조회 2,218
18년 전 조회 1,925
18년 전 조회 1,682
18년 전 조회 2,661
18년 전 조회 1,709
18년 전 조회 1,586
18년 전 조회 4,769
18년 전 조회 1,814
18년 전 조회 1,872
18년 전 조회 1,878
18년 전 조회 1,999
18년 전 조회 3,653
18년 전 조회 1,681
18년 전 조회 1,558
18년 전 조회 1,386
18년 전 조회 1,885
18년 전 조회 1,934
18년 전 조회 3,681
18년 전 조회 2,006
18년 전 조회 3,147
18년 전 조회 4,768
18년 전 조회 2,907
18년 전 조회 8,078
18년 전 조회 4,090
18년 전 조회 2,775
18년 전 조회 1,553
18년 전 조회 2,654
18년 전 조회 5,069
18년 전 조회 5,244
18년 전 조회 2,124
18년 전 조회 4,378
18년 전 조회 4,124
18년 전 조회 4,179
18년 전 조회 2,297
18년 전 조회 4,223
18년 전 조회 2,203
18년 전 조회 3,315
18년 전 조회 4,946
18년 전 조회 1,984
18년 전 조회 3,448
18년 전 조회 1,671
18년 전 조회 2,767
18년 전 조회 1,702
18년 전 조회 2,746
18년 전 조회 2,580
18년 전 조회 1,586
18년 전 조회 1,523
18년 전 조회 1,771
18년 전 조회 2,273
18년 전 조회 2,052
18년 전 조회 2,406
18년 전 조회 4,940
18년 전 조회 1,851
18년 전 조회 1,287
18년 전 조회 1,409
18년 전 조회 1,371
18년 전 조회 1,111
18년 전 조회 1,104
18년 전 조회 1,440
18년 전 조회 1,396
18년 전 조회 2,388
18년 전 조회 1,260
18년 전 조회 1,642
18년 전 조회 2,111
18년 전 조회 1,309
18년 전 조회 2,856
18년 전 조회 1,305
18년 전 조회 1,683
18년 전 조회 1,535
18년 전 조회 1,486
18년 전 조회 1,262
18년 전 조회 1,104
18년 전 조회 1,695
18년 전 조회 1,133
18년 전 조회 3,643
18년 전 조회 1,741
18년 전 조회 1,822
18년 전 조회 1,145
18년 전 조회 1,884
18년 전 조회 1,132
18년 전 조회 1,199
18년 전 조회 1,051
18년 전 조회 1,029
18년 전 조회 1,121
18년 전 조회 2,607
18년 전 조회 1,575
18년 전 조회 1,664
18년 전 조회 1,226
18년 전 조회 1,892
18년 전 조회 1,546
18년 전 조회 1,508
18년 전 조회 1,735