리자

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

· 18년 전 · 2808
<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,897
18년 전 조회 2,223
18년 전 조회 2,400
18년 전 조회 2,956
18년 전 조회 3,045
18년 전 조회 4,208
18년 전 조회 6,205
18년 전 조회 2,149
18년 전 조회 2,266
18년 전 조회 1,962
18년 전 조회 1,724
18년 전 조회 2,711
18년 전 조회 1,754
18년 전 조회 1,629
18년 전 조회 4,807
18년 전 조회 1,860
18년 전 조회 1,905
18년 전 조회 1,911
18년 전 조회 2,042
18년 전 조회 3,710
18년 전 조회 1,719
18년 전 조회 1,597
18년 전 조회 1,433
18년 전 조회 1,927
18년 전 조회 1,970
18년 전 조회 3,738
18년 전 조회 2,061
18년 전 조회 3,192
18년 전 조회 4,822
18년 전 조회 2,950
18년 전 조회 8,122
18년 전 조회 4,129
18년 전 조회 2,824
18년 전 조회 1,600
18년 전 조회 2,707
18년 전 조회 5,106
18년 전 조회 5,293
18년 전 조회 2,160
18년 전 조회 4,429
18년 전 조회 4,168
18년 전 조회 4,231
18년 전 조회 2,349
18년 전 조회 4,261
18년 전 조회 2,262
18년 전 조회 3,360
18년 전 조회 4,998
18년 전 조회 2,022
18년 전 조회 3,488
18년 전 조회 1,716
18년 전 조회 2,809
18년 전 조회 1,747
18년 전 조회 2,797
18년 전 조회 2,630
18년 전 조회 1,628
18년 전 조회 1,572
18년 전 조회 1,823
18년 전 조회 2,323
18년 전 조회 2,092
18년 전 조회 2,443
18년 전 조회 4,975
18년 전 조회 1,893
18년 전 조회 1,326
18년 전 조회 1,443
18년 전 조회 1,414
18년 전 조회 1,147
18년 전 조회 1,145
18년 전 조회 1,477
18년 전 조회 1,430
18년 전 조회 2,426
18년 전 조회 1,300
18년 전 조회 1,685
18년 전 조회 2,152
18년 전 조회 1,351
18년 전 조회 2,899
18년 전 조회 1,349
18년 전 조회 1,727
18년 전 조회 1,567
18년 전 조회 1,525
18년 전 조회 1,305
18년 전 조회 1,138
18년 전 조회 1,732
18년 전 조회 1,167
18년 전 조회 3,679
18년 전 조회 1,787
18년 전 조회 1,865
18년 전 조회 1,185
18년 전 조회 1,919
18년 전 조회 1,164
18년 전 조회 1,235
18년 전 조회 1,086
18년 전 조회 1,071
18년 전 조회 1,152
18년 전 조회 2,644
18년 전 조회 1,608
18년 전 조회 1,698
18년 전 조회 1,259
18년 전 조회 1,928
18년 전 조회 1,574
18년 전 조회 1,545
18년 전 조회 1,764