리자

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

· 2007-05-08 (화) 09:37:31 · 3927
<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에서 이동 됨]
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,187건
+
제목 글쓴이 날짜 조회
07-07-30 조회 5,128
07-07-30 조회 5,589
07-07-30 조회 5,515
07-07-29 조회 3,923
07-07-29 조회 3,656
07-07-29 조회 4,603
07-07-29 조회 4,463
07-07-28 조회 4,663
07-07-26 조회 4,580
07-07-25 조회 6,231
07-07-24 조회 6,489
07-07-21 조회 4,602
07-07-21 조회 3,958
07-07-21 조회 4,163
07-07-21 조회 3,476
07-07-21 조회 3,311
07-07-21 조회 3,258
07-07-20 조회 4,364
07-07-20 조회 3,506
07-07-20 조회 3,582
07-07-20 조회 3,256
07-07-20 조회 3,713
07-07-20 조회 4,444
07-07-18 조회 5,427
07-07-18 조회 4,626
07-07-16 조회 3,225
07-07-16 조회 3,149
07-07-13 조회 4,126
07-07-12 조회 2,842
07-07-09 조회 3,235
07-07-07 조회 3,474
07-07-07 조회 3,375
07-07-07 조회 3,498
07-07-06 조회 5,316
07-07-06 조회 3,043
07-07-06 조회 5,735
07-07-06 조회 4,292
07-07-06 조회 3,475
07-07-06 조회 4,517
07-07-06 조회 4,136
07-07-05 조회 4,124
07-07-05 조회 6,879
07-07-04 조회 3,495
07-07-02 조회 4,652
07-06-30 조회 4,533
07-06-29 조회 4,932
07-06-29 조회 4,462
07-06-28 조회 3,648
07-06-23 조회 3,305
07-06-21 조회 3,770
07-06-20 조회 7,438
07-06-20 조회 4,048
07-06-20 조회 5,786
07-06-19 조회 3,240
07-06-19 조회 1.1만
07-06-17 조회 3,704
07-06-16 조회 2,808
07-06-15 조회 4,212
07-06-12 조회 4,167
07-06-11 조회 4,046
07-06-11 조회 3,336
07-06-05 조회 3,678
07-06-05 조회 4,231
07-06-05 조회 4,240
07-06-05 조회 5,346
07-06-04 조회 7,409
07-05-31 조회 3,317
07-05-30 조회 3,388
07-05-29 조회 3,086
07-05-29 조회 2,816
07-05-29 조회 3,829
07-05-29 조회 2,910
07-05-29 조회 2,719
07-05-29 조회 5,961
07-05-29 조회 2,975
07-05-29 조회 3,002
07-05-29 조회 3,012
07-05-29 조회 3,124
07-05-29 조회 4,814
07-05-29 조회 2,812
07-05-29 조회 2,677
07-05-29 조회 2,495
07-05-29 조회 3,042
07-05-29 조회 3,081
07-05-28 조회 5,006
07-05-26 조회 3,296
07-05-20 조회 4,327
07-05-18 조회 6,072
07-05-18 조회 4,124
07-05-17 조회 9,240
07-05-17 조회 5,283
07-05-17 조회 3,951
07-05-16 조회 2,695
07-05-16 조회 3,839
07-05-15 조회 6,265
07-05-14 조회 6,445
07-05-13 조회 3,282
07-05-11 조회 5,594
07-05-10 조회 5,335
07-05-10 조회 5,405