리자

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

· 18년 전 · 2955
<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,055
18년 전 조회 2,370
18년 전 조회 2,557
18년 전 조회 3,104
18년 전 조회 3,188
18년 전 조회 4,359
18년 전 조회 6,341
18년 전 조회 2,299
18년 전 조회 2,407
18년 전 조회 2,110
18년 전 조회 1,858
18년 전 조회 2,858
18년 전 조회 1,892
18년 전 조회 1,775
18년 전 조회 4,961
18년 전 조회 2,014
18년 전 조회 2,058
18년 전 조회 2,060
18년 전 조회 2,191
18년 전 조회 3,848
18년 전 조회 1,876
18년 전 조회 1,755
18년 전 조회 1,574
18년 전 조회 2,068
18년 전 조회 2,112
18년 전 조회 3,881
18년 전 조회 2,207
18년 전 조회 3,364
18년 전 조회 4,980
18년 전 조회 3,099
18년 전 조회 8,271
18년 전 조회 4,288
18년 전 조회 2,983
18년 전 조회 1,765
18년 전 조회 2,859
18년 전 조회 5,266
18년 전 조회 5,439
18년 전 조회 2,317
18년 전 조회 4,569
18년 전 조회 4,331
18년 전 조회 4,369
18년 전 조회 2,501
18년 전 조회 4,421
18년 전 조회 2,406
18년 전 조회 3,516
18년 전 조회 5,151
18년 전 조회 2,168
18년 전 조회 3,639
18년 전 조회 1,857
18년 전 조회 2,956
18년 전 조회 1,911
18년 전 조회 2,945
18년 전 조회 2,776
18년 전 조회 1,793
18년 전 조회 1,735
18년 전 조회 1,975
18년 전 조회 2,477
18년 전 조회 2,261
18년 전 조회 2,612
18년 전 조회 5,137
18년 전 조회 2,037
18년 전 조회 1,466
18년 전 조회 1,595
18년 전 조회 1,568
18년 전 조회 1,287
18년 전 조회 1,293
18년 전 조회 1,625
18년 전 조회 1,578
18년 전 조회 2,580
18년 전 조회 1,449
18년 전 조회 1,832
18년 전 조회 2,313
18년 전 조회 1,494
18년 전 조회 3,064
18년 전 조회 1,497
18년 전 조회 1,871
18년 전 조회 1,727
18년 전 조회 1,660
18년 전 조회 1,452
18년 전 조회 1,287
18년 전 조회 1,894
18년 전 조회 1,329
18년 전 조회 3,841
18년 전 조회 1,945
18년 전 조회 2,024
18년 전 조회 1,348
18년 전 조회 2,088
18년 전 조회 1,321
18년 전 조회 1,392
18년 전 조회 1,230
18년 전 조회 1,223
18년 전 조회 1,309
18년 전 조회 2,807
18년 전 조회 1,763
18년 전 조회 1,863
18년 전 조회 1,411
18년 전 조회 2,076
18년 전 조회 1,722
18년 전 조회 1,700
18년 전 조회 1,916