리자

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

· 18년 전 · 2761
<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,842
18년 전 조회 2,156
18년 전 조회 2,340
18년 전 조회 2,886
18년 전 조회 2,981
18년 전 조회 4,149
18년 전 조회 6,133
18년 전 조회 2,073
18년 전 조회 2,208
18년 전 조회 1,915
18년 전 조회 1,675
18년 전 조회 2,652
18년 전 조회 1,701
18년 전 조회 1,573
18년 전 조회 4,757
18년 전 조회 1,810
18년 전 조회 1,863
18년 전 조회 1,871
18년 전 조회 1,989
18년 전 조회 3,646
18년 전 조회 1,669
18년 전 조회 1,545
18년 전 조회 1,375
18년 전 조회 1,878
18년 전 조회 1,926
18년 전 조회 3,669
18년 전 조회 2,000
18년 전 조회 3,138
18년 전 조회 4,758
18년 전 조회 2,891
18년 전 조회 8,067
18년 전 조회 4,076
18년 전 조회 2,766
18년 전 조회 1,540
18년 전 조회 2,645
18년 전 조회 5,060
18년 전 조회 5,239
18년 전 조회 2,115
18년 전 조회 4,372
18년 전 조회 4,115
18년 전 조회 4,170
18년 전 조회 2,290
18년 전 조회 4,213
18년 전 조회 2,191
18년 전 조회 3,300
18년 전 조회 4,937
18년 전 조회 1,972
18년 전 조회 3,435
18년 전 조회 1,660
18년 전 조회 2,762
18년 전 조회 1,689
18년 전 조회 2,734
18년 전 조회 2,574
18년 전 조회 1,576
18년 전 조회 1,515
18년 전 조회 1,759
18년 전 조회 2,262
18년 전 조회 2,039
18년 전 조회 2,401
18년 전 조회 4,931
18년 전 조회 1,838
18년 전 조회 1,276
18년 전 조회 1,400
18년 전 조회 1,360
18년 전 조회 1,101
18년 전 조회 1,093
18년 전 조회 1,429
18년 전 조회 1,385
18년 전 조회 2,379
18년 전 조회 1,248
18년 전 조회 1,629
18년 전 조회 2,107
18년 전 조회 1,296
18년 전 조회 2,848
18년 전 조회 1,299
18년 전 조회 1,673
18년 전 조회 1,520
18년 전 조회 1,474
18년 전 조회 1,253
18년 전 조회 1,098
18년 전 조회 1,684
18년 전 조회 1,123
18년 전 조회 3,638
18년 전 조회 1,734
18년 전 조회 1,809
18년 전 조회 1,138
18년 전 조회 1,879
18년 전 조회 1,121
18년 전 조회 1,193
18년 전 조회 1,041
18년 전 조회 1,023
18년 전 조회 1,113
18년 전 조회 2,599
18년 전 조회 1,567
18년 전 조회 1,659
18년 전 조회 1,223
18년 전 조회 1,888
18년 전 조회 1,538
18년 전 조회 1,500
18년 전 조회 1,728