리자

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

· 2007-05-08 (화) 09:37:31 · 3938
<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건
+
제목 글쓴이 날짜 조회
09-10-03 조회 3,180
08-02-03 조회 3,481
08-02-03 조회 3,419
08-01-30 조회 4,932
08-01-29 조회 2,804
08-01-27 조회 3,941
08-01-27 조회 2,875
08-01-27 조회 3,149
08-01-26 조회 8,702
08-01-26 조회 3,253
08-01-24 조회 5,307
08-01-23 조회 3,649
08-01-21 조회 3,692
08-01-21 조회 3,438
08-01-21 조회 3,460
08-01-18 조회 3,969
08-01-18 조회 4,605
08-01-18 조회 6,766
08-01-18 조회 4,046
08-01-17 조회 4,035
08-01-17 조회 3,856
08-01-16 조회 3,117
08-01-15 조회 3,498
08-01-14 조회 6,752
08-01-12 조회 4,349
08-01-12 조회 3,915
08-01-12 조회 4,627
08-01-12 조회 3,868
08-01-12 조회 4,162
08-01-11 조회 7,192
08-01-10 조회 3,936
08-01-08 조회 3,469
08-01-08 조회 3,949
08-01-06 조회 2,736
08-01-04 조회 1.1만
08-01-02 조회 5,816
07-12-28 조회 4,751
07-12-24 조회 3,170
07-12-21 조회 4,869
07-12-17 조회 3,651
07-12-14 조회 5,023
07-12-13 조회 6,458
07-12-10 조회 5,100
07-12-10 조회 3,973
07-12-10 조회 4,371
07-12-08 조회 3,733
07-12-07 조회 4,067
07-12-07 조회 3,197
07-12-06 조회 4,941
07-12-04 조회 3,523
07-12-04 조회 3,663
07-12-03 조회 3,429
07-12-03 조회 4,455
07-12-02 조회 3,286
07-11-30 조회 4,027
07-11-30 조회 5,258
07-11-30 조회 5,853
07-11-29 조회 3,707
07-11-27 조회 4,164
07-11-27 조회 5,938
07-11-27 조회 4,038
07-11-26 조회 3,160
07-11-23 조회 4,618
07-11-23 조회 4,349
07-11-22 조회 5,252
07-11-21 조회 3,473
07-11-21 조회 3,599
07-11-21 조회 1.2만
07-11-20 조회 4,980
07-11-16 조회 4,835
07-11-13 조회 4,500
07-11-12 조회 4,222
07-11-10 조회 5,602
07-11-08 조회 6,765
07-11-08 조회 5,092
07-11-07 조회 4,560
07-11-07 조회 5,011
07-11-06 조회 3,559
07-11-06 조회 3,922
07-11-05 조회 5,257
07-11-02 조회 4,138
07-11-01 조회 5,604
07-10-31 조회 3,294
07-10-30 조회 3,760
07-10-29 조회 3,749
07-10-26 조회 5,070
07-10-25 조회 5,156
07-10-25 조회 3,936
07-10-24 조회 3,932
07-10-24 조회 4,252
07-10-24 조회 4,109
07-10-24 조회 3,384
07-10-24 조회 3,498
07-10-23 조회 6,140
07-10-23 조회 5,532
07-10-22 조회 4,266
07-10-22 조회 3,642
07-10-22 조회 4,184
07-10-22 조회 3,764
07-10-19 조회 4,821