리자

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

· 18년 전 · 2757
<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,131
18년 전 조회 2,072
18년 전 조회 2,207
18년 전 조회 1,915
18년 전 조회 1,674
18년 전 조회 2,652
18년 전 조회 1,701
18년 전 조회 1,571
18년 전 조회 4,756
18년 전 조회 1,808
18년 전 조회 1,859
18년 전 조회 1,870
18년 전 조회 1,988
18년 전 조회 3,645
18년 전 조회 1,668
18년 전 조회 1,544
18년 전 조회 1,375
18년 전 조회 1,877
18년 전 조회 1,924
18년 전 조회 3,669
18년 전 조회 2,000
18년 전 조회 3,136
18년 전 조회 4,757
18년 전 조회 2,889
18년 전 조회 8,065
18년 전 조회 4,074
18년 전 조회 2,766
18년 전 조회 1,538
18년 전 조회 2,645
18년 전 조회 5,060
18년 전 조회 5,239
18년 전 조회 2,114
18년 전 조회 4,370
18년 전 조회 4,113
18년 전 조회 4,169
18년 전 조회 2,288
18년 전 조회 4,213
18년 전 조회 2,190
18년 전 조회 3,300
18년 전 조회 4,934
18년 전 조회 1,971
18년 전 조회 3,434
18년 전 조회 1,660
18년 전 조회 2,758
18년 전 조회 1,688
18년 전 조회 2,734
18년 전 조회 2,573
18년 전 조회 1,576
18년 전 조회 1,515
18년 전 조회 1,759
18년 전 조회 2,260
18년 전 조회 2,038
18년 전 조회 2,399
18년 전 조회 4,931
18년 전 조회 1,838
18년 전 조회 1,275
18년 전 조회 1,399
18년 전 조회 1,358
18년 전 조회 1,100
18년 전 조회 1,092
18년 전 조회 1,428
18년 전 조회 1,384
18년 전 조회 2,375
18년 전 조회 1,247
18년 전 조회 1,629
18년 전 조회 2,107
18년 전 조회 1,295
18년 전 조회 2,847
18년 전 조회 1,297
18년 전 조회 1,671
18년 전 조회 1,517
18년 전 조회 1,474
18년 전 조회 1,251
18년 전 조회 1,097
18년 전 조회 1,682
18년 전 조회 1,122
18년 전 조회 3,638
18년 전 조회 1,733
18년 전 조회 1,808
18년 전 조회 1,135
18년 전 조회 1,877
18년 전 조회 1,119
18년 전 조회 1,193
18년 전 조회 1,041
18년 전 조회 1,023
18년 전 조회 1,113
18년 전 조회 2,597
18년 전 조회 1,565
18년 전 조회 1,657
18년 전 조회 1,219
18년 전 조회 1,885
18년 전 조회 1,537
18년 전 조회 1,499
18년 전 조회 1,727