리자

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

· 18년 전 · 2739
<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,821
18년 전 조회 2,139
18년 전 조회 2,317
18년 전 조회 2,869
18년 전 조회 2,961
18년 전 조회 4,125
18년 전 조회 6,115
18년 전 조회 2,053
18년 전 조회 2,185
18년 전 조회 1,893
18년 전 조회 1,653
18년 전 조회 2,629
18년 전 조회 1,688
18년 전 조회 1,557
18년 전 조회 4,732
18년 전 조회 1,786
18년 전 조회 1,839
18년 전 조회 1,846
18년 전 조회 1,971
18년 전 조회 3,624
18년 전 조회 1,650
18년 전 조회 1,523
18년 전 조회 1,353
18년 전 조회 1,857
18년 전 조회 1,904
18년 전 조회 3,649
18년 전 조회 1,978
18년 전 조회 3,110
18년 전 조회 4,736
18년 전 조회 2,867
18년 전 조회 8,048
18년 전 조회 4,058
18년 전 조회 2,739
18년 전 조회 1,519
18년 전 조회 2,621
18년 전 조회 5,037
18년 전 조회 5,218
18년 전 조회 2,094
18년 전 조회 4,353
18년 전 조회 4,096
18년 전 조회 4,148
18년 전 조회 2,271
18년 전 조회 4,191
18년 전 조회 2,173
18년 전 조회 3,283
18년 전 조회 4,917
18년 전 조회 1,953
18년 전 조회 3,411
18년 전 조회 1,643
18년 전 조회 2,740
18년 전 조회 1,668
18년 전 조회 2,712
18년 전 조회 2,550
18년 전 조회 1,554
18년 전 조회 1,498
18년 전 조회 1,739
18년 전 조회 2,240
18년 전 조회 2,013
18년 전 조회 2,383
18년 전 조회 4,913
18년 전 조회 1,821
18년 전 조회 1,260
18년 전 조회 1,378
18년 전 조회 1,338
18년 전 조회 1,079
18년 전 조회 1,070
18년 전 조회 1,405
18년 전 조회 1,364
18년 전 조회 2,352
18년 전 조회 1,231
18년 전 조회 1,608
18년 전 조회 2,087
18년 전 조회 1,272
18년 전 조회 2,824
18년 전 조회 1,275
18년 전 조회 1,650
18년 전 조회 1,498
18년 전 조회 1,453
18년 전 조회 1,234
18년 전 조회 1,076
18년 전 조회 1,661
18년 전 조회 1,100
18년 전 조회 3,618
18년 전 조회 1,712
18년 전 조회 1,788
18년 전 조회 1,112
18년 전 조회 1,851
18년 전 조회 1,097
18년 전 조회 1,167
18년 전 조회 1,015
18년 전 조회 1,003
18년 전 조회 1,091
18년 전 조회 2,576
18년 전 조회 1,544
18년 전 조회 1,632
18년 전 조회 1,200
18년 전 조회 1,868
18년 전 조회 1,514
18년 전 조회 1,482
18년 전 조회 1,707
🐛 버그신고