리자

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

· 2007-05-08 (화) 09:37:31 · 3872
<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-07-16 조회 3,102
07-07-06 조회 2,972
07-07-06 조회 3,422
07-06-23 조회 3,242
07-06-16 조회 2,753
07-05-20 조회 4,247
07-05-09 조회 3,426
07-05-09 조회 6,068
07-05-04 조회 2,665
07-04-30 조회 9,805
07-04-27 조회 4,304
07-04-26 조회 3,419
07-04-25 조회 5,244
07-04-18 조회 7,754
07-04-13 조회 3,088
07-04-12 조회 6,603
07-04-12 조회 5,010
07-04-12 조회 3,313
07-04-11 조회 5,686
07-04-05 조회 6,336
07-03-24 조회 4,389
07-03-20 조회 3,709
07-03-18 조회 3,972
07-03-18 조회 4,725
07-03-17 조회 4,215
07-03-16 조회 4,115
07-03-15 조회 5,264
07-03-13 조회 5,366
07-03-13 조회 3,558
07-03-08 조회 4,474
07-03-08 조회 3,955
07-03-08 조회 3,265
07-03-08 조회 4,155
07-03-05 조회 4,393
07-03-04 조회 2,889
07-03-01 조회 5,926
07-02-28 조회 3,213
07-02-27 조회 4,388
07-02-26 조회 3,287
07-02-26 조회 3,007
07-02-23 조회 3,641
07-02-23 조회 3,611
07-02-22 조회 3,990
07-02-22 조회 3,799
07-02-19 조회 3,825
07-02-17 조회 4,838
07-02-14 조회 8,141
07-02-12 조회 3,915
07-02-10 조회 3,520
07-02-02 조회 3,772
07-01-31 조회 3,444
07-01-29 조회 3,308
07-01-25 조회 5,080
07-01-21 조회 3,231
07-01-19 조회 3,022
06-12-15 조회 4,016
06-12-15 조회 4,426
06-12-15 조회 2,920
06-12-15 조회 4,462
06-12-15 조회 3,365
06-12-15 조회 4,068
06-12-15 조회 3,015
06-12-15 조회 2,735
06-12-15 조회 4,607
06-12-15 조회 3,155
06-12-15 조회 3,250
06-12-07 조회 4,694
06-12-07 조회 3,985
06-12-04 조회 4,623
06-11-27 조회 3,674
06-11-21 조회 3,991
06-11-15 조회 3,427
06-11-04 조회 3,309
06-10-29 조회 3,962
06-10-13 조회 3,825
06-10-13 조회 4,195
06-10-13 조회 4,156
06-10-12 조회 5,347
06-10-12 조회 4,259
06-10-04 조회 3,753
06-10-02 조회 4,539
06-09-29 조회 3,028
06-09-26 조회 3,367
06-09-26 조회 3,631
06-09-26 조회 3,270
06-09-26 조회 3,421
06-09-26 조회 4,329
06-09-25 조회 4,629
06-09-22 조회 4,961
06-09-22 조회 3,533
06-09-21 조회 4,304
06-09-21 조회 4,314
06-09-21 조회 3,528
06-09-21 조회 5,179
06-09-21 조회 3,705
06-09-21 조회 3,443
06-09-20 조회 3,006
06-09-15 조회 3,130
06-09-13 조회 3,435
06-09-11 조회 3,256