리자

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

· 2007-05-08 (화) 09:37:31 · 3830
<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-01-27 조회 3,806
08-01-26 조회 8,565
08-01-21 조회 3,315
08-01-08 조회 3,766
07-12-21 조회 4,706
07-12-14 조회 4,860
07-12-13 조회 6,307
07-12-10 조회 4,104
07-12-03 조회 3,253
07-12-03 조회 4,295
07-11-27 조회 5,790
07-11-26 조회 2,997
07-11-22 조회 5,113
07-11-21 조회 3,326
07-11-21 조회 1.1만
07-11-12 조회 4,072
07-11-07 조회 4,835
07-10-29 조회 3,584
07-10-25 조회 4,999
07-10-24 조회 3,792
07-10-23 조회 5,982
07-10-09 조회 4,147
07-10-09 조회 4,605
07-10-09 조회 3,202
07-10-09 조회 3,561
07-09-27 조회 3,863
07-09-27 조회 3,090
07-09-15 조회 4,017
07-09-13 조회 2,790
07-09-13 조회 3,251
07-08-07 조회 3,278
07-08-04 조회 3,425
07-07-30 조회 5,426
07-07-29 조회 3,790
07-07-29 조회 4,458
07-07-21 조회 3,105
07-07-20 조회 3,147
07-07-20 조회 4,318
07-07-07 조회 3,387
07-07-06 조회 5,211
07-07-06 조회 5,609
07-07-05 조회 6,747
07-07-04 조회 3,382
07-06-11 조회 3,901
07-06-04 조회 7,243
07-05-28 조회 4,874
07-05-14 조회 6,341
07-05-10 조회 5,287
07-05-09 조회 3,388
07-05-04 조회 3,686
07-04-27 조회 3,329
07-04-25 조회 4,648
07-04-19 조회 3,614
07-04-16 조회 3,221
07-04-13 조회 3,838
07-04-12 조회 4,560
07-04-12 조회 4,773
07-04-11 조회 3,403
07-04-08 조회 5,132
07-04-07 조회 3,236
07-03-29 조회 3,544
07-03-27 조회 3,751
07-03-21 조회 5,148
07-03-15 조회 3,283
07-03-11 조회 3,301
07-03-10 조회 4,939
07-03-09 조회 3,943
07-03-08 조회 4,824
07-03-05 조회 2,945
07-03-02 조회 3,033
07-03-02 조회 3,872
07-02-26 조회 2,921
07-02-26 조회 3,013
07-02-23 조회 4,262
07-02-23 조회 3,329
07-02-23 조회 3,333
07-02-23 조회 3,514
07-02-22 조회 3,152
07-02-21 조회 4,804
07-02-20 조회 4,605
07-02-14 조회 3,751
07-02-12 조회 5,342
07-02-11 조회 4,774
07-02-10 조회 4,079
07-02-09 조회 3,855
07-02-08 조회 4,520
07-02-03 조회 4,115
07-02-02 조회 3,489
07-01-09 조회 3,577
07-01-08 조회 3,948
06-12-26 조회 4,644
06-12-21 조회 3,752
06-12-15 조회 4,162
06-12-15 조회 7,442
06-12-15 조회 3,171
06-12-15 조회 3,189
06-12-15 조회 3,465
06-12-15 조회 3,121
06-12-15 조회 4,540
06-12-15 조회 3,138