리자

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

· 2007-05-08 (화) 09:37:31 · 3931
<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건
+
제목 글쓴이 날짜 조회
08-06-15 조회 3,217
08-06-15 조회 2,441
08-06-14 조회 2,779
08-06-14 조회 3,683
08-06-14 조회 3,370
08-06-12 조회 2,246
08-06-11 조회 2,290
08-06-11 조회 2,383
08-06-11 조회 7,413
08-06-11 조회 7,143
08-06-08 조회 3,316
08-06-07 조회 2,249
08-06-05 조회 2,378
08-06-05 조회 3,349
08-06-05 조회 2,718
08-06-05 조회 2,370
08-06-05 조회 2,393
08-06-04 조회 2,317
08-06-03 조회 2,311
08-06-03 조회 5,385
08-06-03 조회 3,618
08-06-02 조회 2,914
08-06-02 조회 4,061
08-06-01 조회 2,670
08-05-31 조회 2,371
08-05-31 조회 2,382
08-05-31 조회 2,470
08-05-30 조회 2,340
08-05-29 조회 2,490
08-05-29 조회 3,762
08-05-27 조회 5,593
08-05-26 조회 2,437
08-05-26 조회 5,345
08-05-25 조회 5,435
08-05-24 조회 2,497
08-05-23 조회 3,507
08-05-23 조회 2,923
08-05-23 조회 4,676
08-05-22 조회 2,680
08-05-21 조회 5,019
08-05-21 조회 4,803
08-05-21 조회 3,950
08-05-20 조회 4,552
08-05-20 조회 4,128
08-05-20 조회 3,352
08-05-20 조회 4,629
08-05-20 조회 3,971
08-05-20 조회 4,859
08-05-19 조회 2,402
08-05-16 조회 3,534
08-05-15 조회 2,595
08-05-15 조회 2,420
08-05-15 조회 2,409
08-05-14 조회 2,353
08-05-13 조회 2,812
08-05-13 조회 4,217
08-05-13 조회 4,632
08-05-09 조회 4,402
08-05-08 조회 3,159
08-05-08 조회 5,313
08-05-08 조회 2,661
08-05-07 조회 2,365
08-05-07 조회 2,511
08-05-07 조회 2,316
08-05-01 조회 2,631
08-05-01 조회 2,980
08-04-29 조회 3,829
08-04-28 조회 3,652
08-04-26 조회 2,672
08-04-26 조회 2,422
08-04-26 조회 3,699
08-04-25 조회 4,124
08-04-23 조회 4,561
08-04-22 조회 4,523
08-04-22 조회 3,654
08-04-22 조회 5,229
08-04-22 조회 4,605
08-04-22 조회 6,990
08-04-22 조회 4,044
08-04-21 조회 3,192
08-04-21 조회 3,239
08-04-21 조회 3,175
08-04-21 조회 3,001
08-04-21 조회 4,100
08-04-20 조회 3,272
08-04-20 조회 2,948
08-04-20 조회 3,473
08-04-19 조회 2,381
08-04-18 조회 3,093
08-04-18 조회 4,425
08-04-17 조회 3,665
08-04-17 조회 3,126
08-04-17 조회 3,329
08-04-17 조회 2,617
08-04-17 조회 3,012
08-04-17 조회 2,499
08-04-17 조회 3,050
08-04-17 조회 3,111
08-04-17 조회 2,301
08-04-17 조회 4,588