리자

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

· 2007-05-08 (화) 09:37:31 · 3875
<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건
+
제목 글쓴이 날짜 조회
07-10-13 조회 5,180
07-10-03 조회 4,144
07-10-03 조회 3,353
07-10-03 조회 2,592
07-10-03 조회 4,666
07-10-02 조회 3,016
07-10-01 조회 3,649
07-09-28 조회 3,553
07-09-27 조회 4,611
07-08-16 조회 6,449
07-08-04 조회 2,891
07-07-25 조회 6,172
07-07-05 조회 4,052
07-07-02 조회 4,592
07-06-30 조회 4,483
07-06-20 조회 7,387
07-06-20 조회 3,997
07-06-05 조회 4,172
07-05-26 조회 3,217
07-05-17 조회 9,204
07-05-17 조회 5,247
07-05-04 조회 6,164
07-04-15 조회 6,254
07-04-13 조회 4,051
07-04-11 조회 3,443
07-03-20 조회 3,614
07-03-02 조회 6,825
07-02-27 조회 6,093
07-02-22 조회 4,512
07-01-30 조회 6,346
07-01-30 조회 1만
06-12-20 조회 3,821
06-12-18 조회 4,669
06-12-15 조회 4,624
06-12-15 조회 3,858
06-12-15 조회 3,262
06-11-30 조회 3,688
06-11-27 조회 4,601
06-10-24 조회 6,496
06-10-17 조회 4,808
06-09-22 조회 4,556
06-09-21 조회 6,061
06-09-21 조회 3,966
06-09-15 조회 6,596
06-08-20 조회 3,761
06-07-19 조회 3,391
06-07-14 조회 4,277
06-07-14 조회 4,136
06-07-11 조회 5,748
06-06-08 조회 4,333
06-06-08 조회 4,244
06-05-24 조회 3,550
06-05-24 조회 4,930
06-05-17 조회 3,650
06-05-16 조회 4,398
06-05-14 조회 6,089
06-05-12 조회 3,669
06-05-06 조회 4,297
06-05-06 조회 4,374
06-05-06 조회 3,689
06-05-06 조회 3,751
06-05-06 조회 4,210
06-04-25 조회 4,078
06-03-23 조회 5,538
06-01-20 조회 4,114
06-01-04 조회 4,321
05-12-30 조회 4,191
05-12-21 조회 4,871
05-11-09 조회 4,074
05-11-09 조회 3,852
05-10-09 조회 3,491
05-09-21 조회 6,886
05-08-14 조회 4,376
05-08-04 조회 5,562
05-07-14 조회 4,628
05-06-15 조회 5,028
05-04-23 조회 4,599
05-04-20 조회 5,061
05-04-19 조회 1.1만
05-04-19 조회 6,025
05-03-15 조회 3,854
05-03-15 조회 4,299
05-03-13 조회 2,979
05-03-13 조회 3,483
05-03-13 조회 3,489
05-03-13 조회 2,781
05-03-13 조회 5,806
05-03-13 조회 5,440
05-03-13 조회 4,365
05-03-13 조회 4,662
05-03-13 조회 7,929
05-03-13 조회 4,424
05-03-13 조회 3,506
05-03-13 조회 3,501
05-03-13 조회 8,047
05-03-13 조회 5,516
05-03-13 조회 4,167
05-03-12 조회 3,816
05-03-12 조회 4,513
05-02-24 조회 4,662