리자

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

· 18년 전 · 2754
<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년 전 조회 2,839
18년 전 조회 2,151
18년 전 조회 2,333
18년 전 조회 2,883
18년 전 조회 2,979
18년 전 조회 4,140
18년 전 조회 6,126
18년 전 조회 2,070
18년 전 조회 2,204
18년 전 조회 1,911
18년 전 조회 1,669
18년 전 조회 2,647
18년 전 조회 1,698
18년 전 조회 1,569
18년 전 조회 4,749
18년 전 조회 1,802
18년 전 조회 1,857
18년 전 조회 1,865
18년 전 조회 1,984
18년 전 조회 3,638
18년 전 조회 1,665
18년 전 조회 1,540
18년 전 조회 1,370
18년 전 조회 1,875
18년 전 조회 1,920
18년 전 조회 3,662
18년 전 조회 1,991
18년 전 조회 3,136
18년 전 조회 4,752
18년 전 조회 2,885
18년 전 조회 8,061
18년 전 조회 4,070
18년 전 조회 2,759
18년 전 조회 1,535
18년 전 조회 2,638
18년 전 조회 5,057
18년 전 조회 5,234
18년 전 조회 2,111
18년 전 조회 4,366
18년 전 조회 4,111
18년 전 조회 4,164
18년 전 조회 2,286
18년 전 조회 4,206
18년 전 조회 2,187
18년 전 조회 3,295
18년 전 조회 4,930
18년 전 조회 1,968
18년 전 조회 3,427
18년 전 조회 1,655
18년 전 조회 2,755
18년 전 조회 1,687
18년 전 조회 2,729
18년 전 조회 2,566
18년 전 조회 1,572
18년 전 조회 1,512
18년 전 조회 1,757
18년 전 조회 2,256
18년 전 조회 2,033
18년 전 조회 2,395
18년 전 조회 4,928
18년 전 조회 1,837
18년 전 조회 1,271
18년 전 조회 1,393
18년 전 조회 1,352
18년 전 조회 1,093
18년 전 조회 1,087
18년 전 조회 1,423
18년 전 조회 1,379
18년 전 조회 2,371
18년 전 조회 1,245
18년 전 조회 1,620
18년 전 조회 2,102
18년 전 조회 1,288
18년 전 조회 2,844
18년 전 조회 1,295
18년 전 조회 1,665
18년 전 조회 1,513
18년 전 조회 1,471
18년 전 조회 1,247
18년 전 조회 1,091
18년 전 조회 1,677
18년 전 조회 1,118
18년 전 조회 3,633
18년 전 조회 1,732
18년 전 조회 1,807
18년 전 조회 1,131
18년 전 조회 1,867
18년 전 조회 1,113
18년 전 조회 1,184
18년 전 조회 1,038
18년 전 조회 1,021
18년 전 조회 1,111
18년 전 조회 2,593
18년 전 조회 1,559
18년 전 조회 1,651
18년 전 조회 1,214
18년 전 조회 1,881
18년 전 조회 1,529
18년 전 조회 1,495
18년 전 조회 1,721