리자

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

· 2007-05-08 (화) 09:37:31 · 3834
<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-05-10 조회 5,289
07-05-09 조회 3,385
07-05-09 조회 5,322
07-05-09 조회 3,395
07-05-09 조회 4,477
07-05-09 조회 6,033
07-05-08 조회 3,092
07-05-08 조회 4,473
07-05-08 조회 2,795
07-05-08 조회 3,835
07-05-07 조회 2,844
07-05-05 조회 3,879
07-05-04 조회 3,689
07-05-04 조회 2,673
07-05-04 조회 2,612
07-05-04 조회 2,835
07-05-04 조회 3,425
07-05-04 조회 3,169
07-05-04 조회 3,518
07-05-04 조회 6,117
07-05-04 조회 2,890
07-05-04 조회 2,330
07-05-04 조회 2,448
07-05-04 조회 2,424
07-05-04 조회 2,174
07-05-04 조회 2,133
07-05-04 조회 2,481
07-05-04 조회 2,463
07-05-04 조회 3,417
07-05-04 조회 2,331
07-05-04 조회 2,720
07-05-04 조회 3,223
07-05-04 조회 2,361
07-05-04 조회 3,943
07-05-04 조회 2,407
07-05-04 조회 2,789
07-05-04 조회 2,622
07-05-04 조회 2,530
07-05-04 조회 2,355
07-05-04 조회 2,193
07-05-04 조회 2,811
07-05-04 조회 2,200
07-05-04 조회 4,779
07-05-04 조회 2,806
07-05-02 조회 2,917
07-05-02 조회 2,249
07-05-02 조회 2,980
07-05-02 조회 2,216
07-05-02 조회 2,278
07-05-02 조회 2,119
07-05-02 조회 2,089
07-05-02 조회 2,175
07-05-02 조회 3,684
07-05-01 조회 2,647
07-05-01 조회 2,747
07-05-01 조회 2,307
07-05-01 조회 2,969
07-05-01 조회 2,634
07-05-01 조회 2,596
07-05-01 조회 2,816
07-05-01 조회 2,098
07-05-01 조회 2,541
07-05-01 조회 3,405
07-05-01 조회 2,264
07-05-01 조회 2,446
07-05-01 조회 2,677
07-05-01 조회 2,293
07-05-01 조회 2,092
07-05-01 조회 2,304
07-05-01 조회 2,647
07-05-01 조회 2,767
07-05-01 조회 2,692
07-05-01 조회 2,308
07-04-30 조회 9,768
07-04-30 조회 3,083
07-04-30 조회 2,638
07-04-30 조회 2,598
07-04-30 조회 2,934
07-04-30 조회 2,972
07-04-30 조회 2,347
07-04-30 조회 2,085
07-04-30 조회 3,892
07-04-30 조회 4,277
07-04-30 조회 3,331
07-04-30 조회 2,720
07-04-30 조회 2,549
07-04-30 조회 1,980
07-04-28 조회 2,900
07-04-28 조회 6,416
07-04-27 조회 4,001
07-04-27 조회 3,336
07-04-27 조회 4,266
07-04-26 조회 3,665
07-04-26 조회 3,380
07-04-26 조회 5,678
07-04-26 조회 4,661
07-04-25 조회 4,657
07-04-25 조회 5,170
07-04-25 조회 3,089
07-04-22 조회 2,872