리자

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

· 18년 전 · 3021
<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에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
18년 전 조회 3,128
18년 전 조회 2,443
18년 전 조회 2,623
18년 전 조회 3,174
18년 전 조회 3,259
18년 전 조회 4,430
18년 전 조회 6,413
18년 전 조회 2,370
18년 전 조회 2,477
18년 전 조회 2,183
18년 전 조회 1,933
18년 전 조회 2,907
18년 전 조회 1,967
18년 전 조회 1,835
18년 전 조회 5,030
18년 전 조회 2,082
18년 전 조회 2,123
18년 전 조회 2,126
18년 전 조회 2,255
18년 전 조회 3,914
18년 전 조회 1,940
18년 전 조회 1,808
18년 전 조회 1,629
18년 전 조회 2,139
18년 전 조회 2,173
18년 전 조회 3,946
18년 전 조회 2,266
18년 전 조회 3,420
18년 전 조회 5,040
18년 전 조회 3,172
18년 전 조회 8,362
18년 전 조회 4,358
18년 전 조회 3,053
18년 전 조회 1,824
18년 전 조회 2,926
18년 전 조회 5,340
18년 전 조회 5,508
18년 전 조회 2,383
18년 전 조회 4,638
18년 전 조회 4,408
18년 전 조회 4,434
18년 전 조회 2,570
18년 전 조회 4,491
18년 전 조회 2,459
18년 전 조회 3,574
18년 전 조회 5,216
18년 전 조회 2,249
18년 전 조회 3,701
18년 전 조회 1,921
18년 전 조회 3,022
18년 전 조회 1,969
18년 전 조회 3,001
18년 전 조회 2,836
18년 전 조회 1,853
18년 전 조회 1,804
18년 전 조회 2,036
18년 전 조회 2,548
18년 전 조회 2,334
18년 전 조회 2,680
18년 전 조회 5,199
18년 전 조회 2,101
18년 전 조회 1,530
18년 전 조회 1,658
18년 전 조회 1,617
18년 전 조회 1,355
18년 전 조회 1,350
18년 전 조회 1,692
18년 전 조회 1,642
18년 전 조회 2,634
18년 전 조회 1,516
18년 전 조회 1,889
18년 전 조회 2,379
18년 전 조회 1,563
18년 전 조회 3,115
18년 전 조회 1,553
18년 전 조회 1,940
18년 전 조회 1,785
18년 전 조회 1,720
18년 전 조회 1,526
18년 전 조회 1,362
18년 전 조회 1,972
18년 전 조회 1,391
18년 전 조회 3,923
18년 전 조회 2,008
18년 전 조회 2,089
18년 전 조회 1,411
18년 전 조회 2,155
18년 전 조회 1,396
18년 전 조회 1,458
18년 전 조회 1,297
18년 전 조회 1,287
18년 전 조회 1,371
18년 전 조회 2,870
18년 전 조회 1,830
18년 전 조회 1,923
18년 전 조회 1,483
18년 전 조회 2,150
18년 전 조회 1,797
18년 전 조회 1,772
18년 전 조회 1,979