리자

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

· 18년 전 · 2874
<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,959
18년 전 조회 2,285
18년 전 조회 2,478
18년 전 조회 3,025
18년 전 조회 3,112
18년 전 조회 4,270
18년 전 조회 6,253
18년 전 조회 2,218
18년 전 조회 2,326
18년 전 조회 2,033
18년 전 조회 1,777
18년 전 조회 2,781
18년 전 조회 1,819
18년 전 조회 1,689
18년 전 조회 4,874
18년 전 조회 1,925
18년 전 조회 1,974
18년 전 조회 1,975
18년 전 조회 2,104
18년 전 조회 3,766
18년 전 조회 1,783
18년 전 조회 1,662
18년 전 조회 1,490
18년 전 조회 1,991
18년 전 조회 2,035
18년 전 조회 3,797
18년 전 조회 2,133
18년 전 조회 3,269
18년 전 조회 4,890
18년 전 조회 3,018
18년 전 조회 8,192
18년 전 조회 4,204
18년 전 조회 2,890
18년 전 조회 1,665
18년 전 조회 2,773
18년 전 조회 5,182
18년 전 조회 5,354
18년 전 조회 2,226
18년 전 조회 4,492
18년 전 조회 4,240
18년 전 조회 4,289
18년 전 조회 2,414
18년 전 조회 4,337
18년 전 조회 2,323
18년 전 조회 3,429
18년 전 조회 5,072
18년 전 조회 2,094
18년 전 조회 3,550
18년 전 조회 1,783
18년 전 조회 2,875
18년 전 조회 1,822
18년 전 조회 2,863
18년 전 조회 2,699
18년 전 조회 1,710
18년 전 조회 1,646
18년 전 조회 1,892
18년 전 조회 2,400
18년 전 조회 2,178
18년 전 조회 2,516
18년 전 조회 5,044
18년 전 조회 1,959
18년 전 조회 1,390
18년 전 조회 1,512
18년 전 조회 1,485
18년 전 조회 1,206
18년 전 조회 1,215
18년 전 조회 1,554
18년 전 조회 1,505
18년 전 조회 2,501
18년 전 조회 1,375
18년 전 조회 1,757
18년 전 조회 2,225
18년 전 조회 1,418
18년 전 조회 2,977
18년 전 조회 1,423
18년 전 조회 1,796
18년 전 조회 1,639
18년 전 조회 1,590
18년 전 조회 1,378
18년 전 조회 1,203
18년 전 조회 1,811
18년 전 조회 1,246
18년 전 조회 3,757
18년 전 조회 1,867
18년 전 조회 1,940
18년 전 조회 1,264
18년 전 조회 2,002
18년 전 조회 1,239
18년 전 조회 1,319
18년 전 조회 1,158
18년 전 조회 1,147
18년 전 조회 1,231
18년 전 조회 2,723
18년 전 조회 1,686
18년 전 조회 1,774
18년 전 조회 1,328
18년 전 조회 2,004
18년 전 조회 1,645
18년 전 조회 1,618
18년 전 조회 1,841