리자

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

· 18년 전 · 2786
<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,879
18년 전 조회 2,199
18년 전 조회 2,378
18년 전 조회 2,926
18년 전 조회 3,013
18년 전 조회 4,187
18년 전 조회 6,173
18년 전 조회 2,117
18년 전 조회 2,241
18년 전 조회 1,945
18년 전 조회 1,698
18년 전 조회 2,681
18년 전 조회 1,727
18년 전 조회 1,607
18년 전 조회 4,789
18년 전 조회 1,833
18년 전 조회 1,889
18년 전 조회 1,896
18년 전 조회 2,016
18년 전 조회 3,679
18년 전 조회 1,696
18년 전 조회 1,578
18년 전 조회 1,405
18년 전 조회 1,911
18년 전 조회 1,946
18년 전 조회 3,710
18년 전 조회 2,027
18년 전 조회 3,167
18년 전 조회 4,800
18년 전 조회 2,926
18년 전 조회 8,096
18년 전 조회 4,103
18년 전 조회 2,802
18년 전 조회 1,577
18년 전 조회 2,677
18년 전 조회 5,089
18년 전 조회 5,270
18년 전 조회 2,143
18년 전 조회 4,399
18년 전 조회 4,149
18년 전 조회 4,208
18년 전 조회 2,327
18년 전 조회 4,244
18년 전 조회 2,233
18년 전 조회 3,334
18년 전 조회 4,970
18년 전 조회 1,998
18년 전 조회 3,464
18년 전 조회 1,690
18년 전 조회 2,787
18년 전 조회 1,727
18년 전 조회 2,768
18년 전 조회 2,601
18년 전 조회 1,609
18년 전 조회 1,549
18년 전 조회 1,798
18년 전 조회 2,302
18년 전 조회 2,074
18년 전 조회 2,424
18년 전 조회 4,957
18년 전 조회 1,868
18년 전 조회 1,303
18년 전 조회 1,427
18년 전 조회 1,392
18년 전 조회 1,127
18년 전 조회 1,124
18년 전 조회 1,462
18년 전 조회 1,414
18년 전 조회 2,406
18년 전 조회 1,284
18년 전 조회 1,667
18년 전 조회 2,134
18년 전 조회 1,329
18년 전 조회 2,876
18년 전 조회 1,327
18년 전 조회 1,705
18년 전 조회 1,546
18년 전 조회 1,503
18년 전 조회 1,281
18년 전 조회 1,123
18년 전 조회 1,715
18년 전 조회 1,150
18년 전 조회 3,664
18년 전 조회 1,765
18년 전 조회 1,841
18년 전 조회 1,164
18년 전 조회 1,907
18년 전 조회 1,144
18년 전 조회 1,216
18년 전 조회 1,067
18년 전 조회 1,045
18년 전 조회 1,135
18년 전 조회 2,628
18년 전 조회 1,594
18년 전 조회 1,678
18년 전 조회 1,244
18년 전 조회 1,910
18년 전 조회 1,561
18년 전 조회 1,528
18년 전 조회 1,745