리자

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

· 18년 전 · 2798
<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,884
18년 전 조회 2,206
18년 전 조회 2,386
18년 전 조회 2,936
18년 전 조회 3,028
18년 전 조회 4,193
18년 전 조회 6,183
18년 전 조회 2,127
18년 전 조회 2,250
18년 전 조회 1,953
18년 전 조회 1,710
18년 전 조회 2,693
18년 전 조회 1,742
18년 전 조회 1,612
18년 전 조회 4,796
18년 전 조회 1,841
18년 전 조회 1,895
18년 전 조회 1,900
18년 전 조회 2,022
18년 전 조회 3,690
18년 전 조회 1,705
18년 전 조회 1,581
18년 전 조회 1,414
18년 전 조회 1,915
18년 전 조회 1,955
18년 전 조회 3,722
18년 전 조회 2,043
18년 전 조회 3,177
18년 전 조회 4,811
18년 전 조회 2,936
18년 전 조회 8,107
18년 전 조회 4,112
18년 전 조회 2,809
18년 전 조회 1,586
18년 전 조회 2,690
18년 전 조회 5,096
18년 전 조회 5,280
18년 전 조회 2,150
18년 전 조회 4,409
18년 전 조회 4,158
18년 전 조회 4,219
18년 전 조회 2,339
18년 전 조회 4,247
18년 전 조회 2,245
18년 전 조회 3,344
18년 전 조회 4,982
18년 전 조회 2,005
18년 전 조회 3,472
18년 전 조회 1,703
18년 전 조회 2,799
18년 전 조회 1,732
18년 전 조회 2,783
18년 전 조회 2,616
18년 전 조회 1,616
18년 전 조회 1,556
18년 전 조회 1,804
18년 전 조회 2,308
18년 전 조회 2,080
18년 전 조회 2,431
18년 전 조회 4,962
18년 전 조회 1,878
18년 전 조회 1,312
18년 전 조회 1,434
18년 전 조회 1,399
18년 전 조회 1,137
18년 전 조회 1,132
18년 전 조회 1,466
18년 전 조회 1,419
18년 전 조회 2,412
18년 전 조회 1,289
18년 전 조회 1,670
18년 전 조회 2,137
18년 전 조회 1,333
18년 전 조회 2,887
18년 전 조회 1,335
18년 전 조회 1,711
18년 전 조회 1,557
18년 전 조회 1,510
18년 전 조회 1,290
18년 전 조회 1,129
18년 전 조회 1,723
18년 전 조회 1,153
18년 전 조회 3,670
18년 전 조회 1,776
18년 전 조회 1,850
18년 전 조회 1,168
18년 전 조회 1,911
18년 전 조회 1,148
18년 전 조회 1,219
18년 전 조회 1,073
18년 전 조회 1,050
18년 전 조회 1,140
18년 전 조회 2,637
18년 전 조회 1,599
18년 전 조회 1,681
18년 전 조회 1,248
18년 전 조회 1,912
18년 전 조회 1,562
18년 전 조회 1,532
18년 전 조회 1,754