리자

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

· 18년 전 · 2758
<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,841
18년 전 조회 2,156
18년 전 조회 2,337
18년 전 조회 2,885
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,808
18년 전 조회 1,861
18년 전 조회 1,870
18년 전 조회 1,989
18년 전 조회 3,645
18년 전 조회 1,668
18년 전 조회 1,545
18년 전 조회 1,375
18년 전 조회 1,878
18년 전 조회 1,925
18년 전 조회 3,669
18년 전 조회 2,000
18년 전 조회 3,137
18년 전 조회 4,757
18년 전 조회 2,890
18년 전 조회 8,065
18년 전 조회 4,075
18년 전 조회 2,766
18년 전 조회 1,538
18년 전 조회 2,645
18년 전 조회 5,060
18년 전 조회 5,239
18년 전 조회 2,115
18년 전 조회 4,371
18년 전 조회 4,113
18년 전 조회 4,170
18년 전 조회 2,288
18년 전 조회 4,213
18년 전 조회 2,191
18년 전 조회 3,300
18년 전 조회 4,935
18년 전 조회 1,971
18년 전 조회 3,435
18년 전 조회 1,660
18년 전 조회 2,759
18년 전 조회 1,688
18년 전 조회 2,734
18년 전 조회 2,573
18년 전 조회 1,576
18년 전 조회 1,515
18년 전 조회 1,759
18년 전 조회 2,261
18년 전 조회 2,038
18년 전 조회 2,399
18년 전 조회 4,931
18년 전 조회 1,838
18년 전 조회 1,276
18년 전 조회 1,400
18년 전 조회 1,359
18년 전 조회 1,101
18년 전 조회 1,093
18년 전 조회 1,429
18년 전 조회 1,384
18년 전 조회 2,379
18년 전 조회 1,248
18년 전 조회 1,629
18년 전 조회 2,107
18년 전 조회 1,295
18년 전 조회 2,847
18년 전 조회 1,298
18년 전 조회 1,671
18년 전 조회 1,517
18년 전 조회 1,474
18년 전 조회 1,251
18년 전 조회 1,097
18년 전 조회 1,683
18년 전 조회 1,122
18년 전 조회 3,638
18년 전 조회 1,734
18년 전 조회 1,809
18년 전 조회 1,136
18년 전 조회 1,878
18년 전 조회 1,119
18년 전 조회 1,193
18년 전 조회 1,041
18년 전 조회 1,023
18년 전 조회 1,113
18년 전 조회 2,597
18년 전 조회 1,565
18년 전 조회 1,658
18년 전 조회 1,222
18년 전 조회 1,887
18년 전 조회 1,538
18년 전 조회 1,499
18년 전 조회 1,727