리자

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

· 2007-05-08 (화) 09:37:31 · 3878
<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-04-17 조회 4,396
08-03-14 조회 3,247
08-03-08 조회 3,066
08-03-06 조회 3,048
08-03-03 조회 4,346
08-02-20 조회 3,021
08-02-15 조회 3,930
08-02-11 조회 5,087
08-02-09 조회 5,820
08-02-05 조회 3,872
08-01-14 조회 6,675
08-01-11 조회 7,114
08-01-04 조회 1.1만
07-12-10 조회 5,008
07-12-10 조회 3,888
07-12-04 조회 3,424
07-11-29 조회 3,611
07-11-27 조회 3,955
07-11-23 조회 4,543
07-11-23 조회 4,277
07-11-13 조회 4,411
07-10-19 조회 4,880
07-10-17 조회 5,926
07-10-03 조회 5,098
07-10-02 조회 8,852
07-10-02 조회 4,500
07-09-09 조회 3,485
07-07-29 조회 4,369
07-07-28 조회 4,592
07-07-26 조회 4,491
07-06-19 조회 1.1만
07-06-17 조회 3,649
07-06-15 조회 4,144
07-05-31 조회 3,219
07-05-09 조회 5,373
07-05-04 조회 3,224
07-05-04 조회 3,558
07-04-28 조회 6,471
07-04-26 조회 4,710
07-04-14 조회 5,348
07-04-13 조회 3,771
07-04-12 조회 5,944
07-03-27 조회 3,892
07-03-19 조회 3,594
07-03-13 조회 4,666
07-03-07 조회 4,815
07-03-07 조회 3,325
07-02-25 조회 3,694
07-02-21 조회 4,583
07-02-18 조회 5,098
07-02-12 조회 3,452
07-02-02 조회 4,588
07-01-28 조회 6,202
07-01-27 조회 5,700
07-01-25 조회 4,069
07-01-21 조회 4,690
07-01-19 조회 6,622
07-01-19 조회 8,084
07-01-13 조회 3,558
07-01-09 조회 5,206
06-12-27 조회 3,596
06-11-24 조회 3,699
06-11-18 조회 4,208
06-10-17 조회 5,541
06-10-01 조회 4,450
06-09-26 조회 4,339
06-09-25 조회 4,675
06-09-25 조회 4,378
06-09-22 조회 4,905
06-09-22 조회 3,681
06-09-22 조회 4,534
06-09-13 조회 5,333
06-08-27 조회 4,938
06-08-26 조회 6,310
06-08-26 조회 5,621
06-08-23 조회 5,112
06-07-28 조회 7,217
06-07-24 조회 4,672
06-07-23 조회 5,458
06-07-21 조회 5,215
06-07-19 조회 3,105
06-07-19 조회 3,030
06-07-11 조회 3,665
06-07-11 조회 3,960
06-07-11 조회 4,554
06-07-11 조회 4,999
06-07-11 조회 3,618
06-07-11 조회 9,238
06-07-11 조회 4,091
06-07-11 조회 3,320
06-07-11 조회 3,371
06-07-11 조회 3,311
06-07-11 조회 3,107
06-07-07 조회 4,155
06-06-25 조회 4,503
06-06-15 조회 4,494
06-06-14 조회 4,985
06-06-11 조회 3,581
06-06-10 조회 3,956
06-06-09 조회 3,545