리자

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

· 18년 전 · 2793
<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,882
18년 전 조회 2,201
18년 전 조회 2,382
18년 전 조회 2,933
18년 전 조회 3,022
18년 전 조회 4,191
18년 전 조회 6,177
18년 전 조회 2,121
18년 전 조회 2,247
18년 전 조회 1,947
18년 전 조회 1,704
18년 전 조회 2,688
18년 전 조회 1,738
18년 전 조회 1,610
18년 전 조회 4,795
18년 전 조회 1,836
18년 전 조회 1,892
18년 전 조회 1,898
18년 전 조회 2,022
18년 전 조회 3,684
18년 전 조회 1,703
18년 전 조회 1,579
18년 전 조회 1,408
18년 전 조회 1,913
18년 전 조회 1,951
18년 전 조회 3,716
18년 전 조회 2,035
18년 전 조회 3,175
18년 전 조회 4,804
18년 전 조회 2,934
18년 전 조회 8,099
18년 전 조회 4,107
18년 전 조회 2,805
18년 전 조회 1,582
18년 전 조회 2,686
18년 전 조회 5,092
18년 전 조회 5,275
18년 전 조회 2,147
18년 전 조회 4,406
18년 전 조회 4,154
18년 전 조회 4,212
18년 전 조회 2,333
18년 전 조회 4,245
18년 전 조회 2,239
18년 전 조회 3,339
18년 전 조회 4,976
18년 전 조회 2,001
18년 전 조회 3,467
18년 전 조회 1,698
18년 전 조회 2,794
18년 전 조회 1,730
18년 전 조회 2,776
18년 전 조회 2,611
18년 전 조회 1,612
18년 전 조회 1,554
18년 전 조회 1,801
18년 전 조회 2,306
18년 전 조회 2,078
18년 전 조회 2,427
18년 전 조회 4,959
18년 전 조회 1,872
18년 전 조회 1,309
18년 전 조회 1,429
18년 전 조회 1,395
18년 전 조회 1,133
18년 전 조회 1,130
18년 전 조회 1,464
18년 전 조회 1,417
18년 전 조회 2,409
18년 전 조회 1,287
18년 전 조회 1,668
18년 전 조회 2,135
18년 전 조회 1,332
18년 전 조회 2,882
18년 전 조회 1,332
18년 전 조회 1,709
18년 전 조회 1,553
18년 전 조회 1,508
18년 전 조회 1,287
18년 전 조회 1,126
18년 전 조회 1,722
18년 전 조회 1,152
18년 전 조회 3,668
18년 전 조회 1,770
18년 전 조회 1,847
18년 전 조회 1,166
18년 전 조회 1,909
18년 전 조회 1,148
18년 전 조회 1,218
18년 전 조회 1,070
18년 전 조회 1,048
18년 전 조회 1,138
18년 전 조회 2,630
18년 전 조회 1,596
18년 전 조회 1,680
18년 전 조회 1,245
18년 전 조회 1,911
18년 전 조회 1,562
18년 전 조회 1,531
18년 전 조회 1,751