리자

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

· 18년 전 · 2884
<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,979
18년 전 조회 2,296
18년 전 조회 2,490
18년 전 조회 3,038
18년 전 조회 3,124
18년 전 조회 4,284
18년 전 조회 6,264
18년 전 조회 2,223
18년 전 조회 2,333
18년 전 조회 2,043
18년 전 조회 1,791
18년 전 조회 2,786
18년 전 조회 1,833
18년 전 조회 1,703
18년 전 조회 4,885
18년 전 조회 1,942
18년 전 조회 1,986
18년 전 조회 1,989
18년 전 조회 2,112
18년 전 조회 3,779
18년 전 조회 1,794
18년 전 조회 1,675
18년 전 조회 1,503
18년 전 조회 1,998
18년 전 조회 2,046
18년 전 조회 3,805
18년 전 조회 2,142
18년 전 조회 3,283
18년 전 조회 4,901
18년 전 조회 3,030
18년 전 조회 8,205
18년 전 조회 4,214
18년 전 조회 2,902
18년 전 조회 1,675
18년 전 조회 2,781
18년 전 조회 5,194
18년 전 조회 5,370
18년 전 조회 2,243
18년 전 조회 4,499
18년 전 조회 4,249
18년 전 조회 4,303
18년 전 조회 2,427
18년 전 조회 4,351
18년 전 조회 2,337
18년 전 조회 3,436
18년 전 조회 5,083
18년 전 조회 2,110
18년 전 조회 3,564
18년 전 조회 1,793
18년 전 조회 2,885
18년 전 조회 1,831
18년 전 조회 2,875
18년 전 조회 2,709
18년 전 조회 1,722
18년 전 조회 1,654
18년 전 조회 1,908
18년 전 조회 2,413
18년 전 조회 2,190
18년 전 조회 2,531
18년 전 조회 5,056
18년 전 조회 1,971
18년 전 조회 1,403
18년 전 조회 1,530
18년 전 조회 1,495
18년 전 조회 1,221
18년 전 조회 1,227
18년 전 조회 1,562
18년 전 조회 1,517
18년 전 조회 2,512
18년 전 조회 1,386
18년 전 조회 1,770
18년 전 조회 2,238
18년 전 조회 1,426
18년 전 조회 2,991
18년 전 조회 1,435
18년 전 조회 1,804
18년 전 조회 1,650
18년 전 조회 1,598
18년 전 조회 1,387
18년 전 조회 1,213
18년 전 조회 1,818
18년 전 조회 1,256
18년 전 조회 3,771
18년 전 조회 1,876
18년 전 조회 1,950
18년 전 조회 1,275
18년 전 조회 2,012
18년 전 조회 1,251
18년 전 조회 1,325
18년 전 조회 1,171
18년 전 조회 1,160
18년 전 조회 1,243
18년 전 조회 2,736
18년 전 조회 1,694
18년 전 조회 1,789
18년 전 조회 1,339
18년 전 조회 2,013
18년 전 조회 1,652
18년 전 조회 1,630
18년 전 조회 1,849