리자

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

· 18년 전 · 2885
<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,982
18년 전 조회 2,297
18년 전 조회 2,492
18년 전 조회 3,038
18년 전 조회 3,125
18년 전 조회 4,285
18년 전 조회 6,265
18년 전 조회 2,223
18년 전 조회 2,334
18년 전 조회 2,043
18년 전 조회 1,794
18년 전 조회 2,787
18년 전 조회 1,833
18년 전 조회 1,706
18년 전 조회 4,886
18년 전 조회 1,942
18년 전 조회 1,987
18년 전 조회 1,991
18년 전 조회 2,115
18년 전 조회 3,781
18년 전 조회 1,795
18년 전 조회 1,675
18년 전 조회 1,506
18년 전 조회 2,001
18년 전 조회 2,047
18년 전 조회 3,806
18년 전 조회 2,143
18년 전 조회 3,286
18년 전 조회 4,902
18년 전 조회 3,033
18년 전 조회 8,205
18년 전 조회 4,216
18년 전 조회 2,905
18년 전 조회 1,675
18년 전 조회 2,782
18년 전 조회 5,196
18년 전 조회 5,371
18년 전 조회 2,245
18년 전 조회 4,500
18년 전 조회 4,249
18년 전 조회 4,305
18년 전 조회 2,428
18년 전 조회 4,352
18년 전 조회 2,340
18년 전 조회 3,437
18년 전 조회 5,085
18년 전 조회 2,110
18년 전 조회 3,567
18년 전 조회 1,793
18년 전 조회 2,886
18년 전 조회 1,832
18년 전 조회 2,876
18년 전 조회 2,710
18년 전 조회 1,723
18년 전 조회 1,654
18년 전 조회 1,909
18년 전 조회 2,413
18년 전 조회 2,191
18년 전 조회 2,531
18년 전 조회 5,059
18년 전 조회 1,973
18년 전 조회 1,404
18년 전 조회 1,534
18년 전 조회 1,497
18년 전 조회 1,223
18년 전 조회 1,230
18년 전 조회 1,565
18년 전 조회 1,518
18년 전 조회 2,514
18년 전 조회 1,389
18년 전 조회 1,771
18년 전 조회 2,242
18년 전 조회 1,429
18년 전 조회 2,993
18년 전 조회 1,435
18년 전 조회 1,805
18년 전 조회 1,651
18년 전 조회 1,599
18년 전 조회 1,389
18년 전 조회 1,215
18년 전 조회 1,821
18년 전 조회 1,256
18년 전 조회 3,773
18년 전 조회 1,876
18년 전 조회 1,951
18년 전 조회 1,277
18년 전 조회 2,013
18년 전 조회 1,252
18년 전 조회 1,326
18년 전 조회 1,173
18년 전 조회 1,160
18년 전 조회 1,244
18년 전 조회 2,736
18년 전 조회 1,695
18년 전 조회 1,790
18년 전 조회 1,346
18년 전 조회 2,016
18년 전 조회 1,654
18년 전 조회 1,631
18년 전 조회 1,851