리자

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

· 2007-05-08 (화) 09:37:31 · 3828
<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에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
07-04-22 조회 2,886
07-04-22 조회 2,520
07-04-22 조회 2,347
07-04-22 조회 2,264
07-04-21 조회 2,330
07-04-21 조회 2,649
07-04-21 조회 2,009
07-04-21 조회 2,420
07-04-21 조회 2,268
07-04-21 조회 2,321
07-04-20 조회 4,116
07-04-20 조회 2,054
07-04-20 조회 2,275
07-04-20 조회 3,300
07-04-20 조회 3,402
07-04-20 조회 2,428
07-04-20 조회 3,036
07-04-20 조회 2,278
07-04-19 조회 3,612
07-04-18 조회 7,704
07-04-18 조회 4,918
07-04-18 조회 3,326
07-04-17 조회 7,484
07-04-17 조회 3,752
07-04-17 조회 3,795
07-04-17 조회 3,221
07-04-16 조회 3,218
07-04-16 조회 3,209
07-04-16 조회 5,084
07-04-15 조회 5,092
07-04-15 조회 6,197
07-04-14 조회 5,297
07-04-13 조회 3,714
07-04-13 조회 3,036
07-04-13 조회 3,961
07-04-13 조회 3,837
07-04-13 조회 3,340
07-04-12 조회 6,555
07-04-12 조회 5,907
07-04-12 조회 4,960
07-04-12 조회 4,558
07-04-12 조회 3,247
07-04-12 조회 3,276
07-04-12 조회 4,773
07-04-11 조회 3,381
07-04-11 조회 3,618
07-04-11 조회 2,873
07-04-11 조회 5,656
07-04-11 조회 3,288
07-04-11 조회 3,403
07-04-11 조회 5,159
07-04-08 조회 5,132
07-04-07 조회 3,236
07-04-05 조회 3,908
07-04-05 조회 6,302
07-04-04 조회 3,536
07-04-04 조회 4,107
07-04-02 조회 9,760
07-03-31 조회 3,142
07-03-31 조회 4,116
07-03-30 조회 3,720
07-03-30 조회 4,110
07-03-29 조회 3,542
07-03-29 조회 3,611
07-03-27 조회 3,849
07-03-27 조회 5,064
07-03-27 조회 3,749
07-03-26 조회 3,833
07-03-24 조회 4,351
07-03-24 조회 3,996
07-03-23 조회 3,234
07-03-22 조회 3,649
07-03-21 조회 3,665
07-03-21 조회 5,146
07-03-21 조회 5,890
07-03-20 조회 3,454
07-03-20 조회 3,657
07-03-20 조회 3,548
07-03-20 조회 4,922
07-03-19 조회 3,543
07-03-19 조회 3,486
07-03-18 조회 2,820
07-03-18 조회 3,113
07-03-18 조회 3,930
07-03-18 조회 4,687
07-03-17 조회 4,174
07-03-16 조회 4,079
07-03-16 조회 3,115
07-03-15 조회 5,225
07-03-15 조회 3,283
07-03-13 조회 5,318
07-03-13 조회 3,631
07-03-13 조회 3,519
07-03-13 조회 4,618
07-03-13 조회 3,353
07-03-13 조회 3,263
07-03-12 조회 4,399
07-03-11 조회 5,068
07-03-11 조회 3,301
07-03-11 조회 3,486