리자

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

· 2007-05-08 (화) 09:37:31 · 3888
<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,188건
+
제목 글쓴이 날짜 조회
08-10-30 조회 2,713
08-10-30 조회 2,811
08-10-20 조회 2,541
08-10-11 조회 2,447
08-09-20 조회 4,187
08-09-20 조회 2,857
08-09-18 조회 2,743
08-09-18 조회 3,438
08-09-17 조회 3,301
08-09-05 조회 4,640
08-09-03 조회 2,775
08-08-18 조회 2,899
08-08-17 조회 2,637
08-08-13 조회 3,418
08-07-30 조회 3,483
08-07-28 조회 4,359
08-07-22 조회 5,588
08-07-22 조회 4,076
08-07-10 조회 3,045
08-07-08 조회 3,107
08-06-30 조회 3,867
08-06-30 조회 3,350
08-06-30 조회 3,668
08-06-14 조회 2,741
08-06-11 조회 7,103
08-06-05 조회 3,317
08-05-20 조회 4,828
08-05-13 조회 4,172
08-05-08 조회 3,125
08-05-08 조회 5,279
08-04-25 조회 4,075
08-04-22 조회 4,544
08-04-21 조회 3,186
08-04-17 조회 2,567
08-04-17 조회 2,968
08-04-17 조회 2,264
08-04-17 조회 5,235
08-04-17 조회 4,553
08-04-17 조회 4,548
08-04-17 조회 3,332
08-04-17 조회 3,156
08-04-17 조회 3,642
08-04-17 조회 5,004
08-04-17 조회 5,150
08-04-17 조회 3,357
08-04-04 조회 4,617
08-04-04 조회 2,849
08-04-04 조회 2,591
08-04-04 조회 2,818
08-04-04 조회 2,551
08-04-04 조회 2,794
08-04-03 조회 2,681
08-04-03 조회 2,750
08-04-02 조회 3,063
08-04-02 조회 3,219
08-03-31 조회 3,107
08-03-26 조회 4,285
08-03-11 조회 2,971
08-03-11 조회 2,383
08-03-11 조회 2,395
08-03-07 조회 4,230
08-03-07 조회 3,323
08-03-06 조회 4,771
08-03-04 조회 3,401
08-02-19 조회 3,796
08-02-03 조회 3,419
08-01-18 조회 4,006
08-01-15 조회 3,453
08-01-12 조회 4,300
08-01-12 조회 3,870
08-01-12 조회 3,825
07-12-24 조회 3,118
07-11-30 조회 3,961
07-11-08 조회 5,018
07-11-06 조회 3,871
07-10-26 조회 5,013
07-10-24 조회 4,198
07-10-22 조회 3,585
07-10-19 조회 4,770
07-10-09 조회 4,904
07-10-09 조회 6,769
07-10-05 조회 3,104
07-10-05 조회 4,040
07-10-03 조회 7,548
07-10-03 조회 3,595
07-10-03 조회 2,942
07-10-03 조회 2,871
07-09-28 조회 4,713
07-09-27 조회 3,780
07-09-27 조회 3,230
07-09-13 조회 3,381
07-08-28 조회 3,462
07-08-04 조회 4,851
07-08-01 조회 5,545
07-08-01 조회 4,948
07-07-30 조회 5,469
07-07-29 조회 3,614
07-07-21 조회 3,434
07-07-18 조회 5,393
07-07-16 조회 3,188