리자

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

· 2007-05-08 (화) 09:37:31 · 3939
<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-11-25 조회 3,764
08-11-25 조회 2,956
08-11-25 조회 4,532
08-11-25 조회 4,405
08-11-21 조회 4,385
08-11-21 조회 5,313
08-11-20 조회 3,941
08-11-20 조회 3,754
08-11-19 조회 4,021
08-11-19 조회 4,261
08-11-18 조회 4,045
08-11-15 조회 2,921
08-11-14 조회 3,224
08-11-14 조회 2,891
08-11-14 조회 3,284
08-11-13 조회 3,909
08-11-12 조회 1만
08-11-07 조회 4,611
08-11-07 조회 5,597
08-11-03 조회 3,362
08-11-01 조회 5,076
08-11-01 조회 3,029
08-10-30 조회 2,738
08-10-30 조회 3,669
08-10-30 조회 2,765
08-10-30 조회 3,000
08-10-30 조회 2,864
08-10-29 조회 3,945
08-10-29 조회 2,926
08-10-29 조회 2,460
08-10-20 조회 2,593
08-10-18 조회 4,539
08-10-16 조회 3,595
08-10-16 조회 3,398
08-10-14 조회 2,601
08-10-11 조회 3,901
08-10-11 조회 2,496
08-10-09 조회 2,593
08-10-09 조회 2,750
08-10-09 조회 4,216
08-10-08 조회 3,912
08-10-02 조회 3,853
08-10-02 조회 2,599
08-10-02 조회 2,747
08-09-29 조회 4,679
08-09-29 조회 4,307
08-09-26 조회 5,620
08-09-26 조회 3,592
08-09-26 조회 3,659
08-09-26 조회 2,806
08-09-26 조회 3,844
08-09-26 조회 3,583
08-09-26 조회 4,344
08-09-22 조회 3,905
08-09-22 조회 3,090
08-09-22 조회 4,057
08-09-22 조회 3,018
08-09-22 조회 2,666
08-09-21 조회 3,655
08-09-20 조회 4,236
08-09-20 조회 5,508
08-09-20 조회 4,602
08-09-20 조회 2,927
08-09-20 조회 3,324
08-09-20 조회 3,691
08-09-20 조회 3,066
08-09-20 조회 3,257
08-09-20 조회 4,241
08-09-20 조회 3,741
08-09-20 조회 3,322
08-09-19 조회 5,719
08-09-19 조회 4,494
08-09-19 조회 2,808
08-09-18 조회 5,158
08-09-18 조회 4,238
08-09-18 조회 3,614
08-09-18 조회 2,809
08-09-18 조회 3,724
08-09-18 조회 3,516
08-09-17 조회 3,384
08-09-16 조회 3,331
08-09-10 조회 2,544
08-09-09 조회 3,343
08-09-06 조회 4,233
08-09-06 조회 2,795
08-09-06 조회 3,163
08-09-06 조회 2,825
08-09-06 조회 3,056
08-09-06 조회 2,944
08-09-06 조회 2,915
08-09-05 조회 3,913
08-09-05 조회 3,740
08-09-05 조회 3,567
08-09-05 조회 2,787
08-09-05 조회 3,813
08-09-05 조회 5,775
08-09-05 조회 4,233
08-09-05 조회 3,122
08-09-05 조회 3,276
08-09-05 조회 4,702