리자

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

· 18년 전 · 2876
<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,962
18년 전 조회 2,286
18년 전 조회 2,483
18년 전 조회 3,028
18년 전 조회 3,114
18년 전 조회 4,273
18년 전 조회 6,256
18년 전 조회 2,219
18년 전 조회 2,327
18년 전 조회 2,036
18년 전 조회 1,782
18년 전 조회 2,784
18년 전 조회 1,826
18년 전 조회 1,692
18년 전 조회 4,879
18년 전 조회 1,929
18년 전 조회 1,977
18년 전 조회 1,978
18년 전 조회 2,106
18년 전 조회 3,768
18년 전 조회 1,787
18년 전 조회 1,666
18년 전 조회 1,492
18년 전 조회 1,992
18년 전 조회 2,037
18년 전 조회 3,801
18년 전 조회 2,133
18년 전 조회 3,272
18년 전 조회 4,892
18년 전 조회 3,022
18년 전 조회 8,197
18년 전 조회 4,204
18년 전 조회 2,895
18년 전 조회 1,668
18년 전 조회 2,778
18년 전 조회 5,188
18년 전 조회 5,357
18년 전 조회 2,232
18년 전 조회 4,495
18년 전 조회 4,243
18년 전 조회 4,292
18년 전 조회 2,418
18년 전 조회 4,341
18년 전 조회 2,326
18년 전 조회 3,432
18년 전 조회 5,073
18년 전 조회 2,100
18년 전 조회 3,552
18년 전 조회 1,787
18년 전 조회 2,877
18년 전 조회 1,826
18년 전 조회 2,864
18년 전 조회 2,702
18년 전 조회 1,715
18년 전 조회 1,650
18년 전 조회 1,897
18년 전 조회 2,404
18년 전 조회 2,181
18년 전 조회 2,521
18년 전 조회 5,047
18년 전 조회 1,963
18년 전 조회 1,391
18년 전 조회 1,514
18년 전 조회 1,488
18년 전 조회 1,211
18년 전 조회 1,218
18년 전 조회 1,555
18년 전 조회 1,507
18년 전 조회 2,504
18년 전 조회 1,379
18년 전 조회 1,757
18년 전 조회 2,226
18년 전 조회 1,421
18년 전 조회 2,982
18년 전 조회 1,424
18년 전 조회 1,798
18년 전 조회 1,640
18년 전 조회 1,592
18년 전 조회 1,380
18년 전 조회 1,204
18년 전 조회 1,812
18년 전 조회 1,247
18년 전 조회 3,760
18년 전 조회 1,873
18년 전 조회 1,944
18년 전 조회 1,267
18년 전 조회 2,005
18년 전 조회 1,243
18년 전 조회 1,320
18년 전 조회 1,163
18년 전 조회 1,150
18년 전 조회 1,231
18년 전 조회 2,724
18년 전 조회 1,687
18년 전 조회 1,781
18년 전 조회 1,332
18년 전 조회 2,008
18년 전 조회 1,647
18년 전 조회 1,621
18년 전 조회 1,842