리자

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

· 18년 전 · 2893
<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,994
18년 전 조회 2,313
18년 전 조회 2,501
18년 전 조회 3,050
18년 전 조회 3,138
18년 전 조회 4,298
18년 전 조회 6,283
18년 전 조회 2,236
18년 전 조회 2,347
18년 전 조회 2,051
18년 전 조회 1,806
18년 전 조회 2,805
18년 전 조회 1,842
18년 전 조회 1,716
18년 전 조회 4,900
18년 전 조회 1,953
18년 전 조회 2,000
18년 전 조회 2,005
18년 전 조회 2,134
18년 전 조회 3,794
18년 전 조회 1,807
18년 전 조회 1,687
18년 전 조회 1,518
18년 전 조회 2,014
18년 전 조회 2,056
18년 전 조회 3,822
18년 전 조회 2,157
18년 전 조회 3,296
18년 전 조회 4,916
18년 전 조회 3,045
18년 전 조회 8,220
18년 전 조회 4,231
18년 전 조회 2,919
18년 전 조회 1,687
18년 전 조회 2,799
18년 전 조회 5,211
18년 전 조회 5,384
18년 전 조회 2,263
18년 전 조회 4,511
18년 전 조회 4,266
18년 전 조회 4,313
18년 전 조회 2,439
18년 전 조회 4,369
18년 전 조회 2,350
18년 전 조회 3,448
18년 전 조회 5,092
18년 전 조회 2,123
18년 전 조회 3,580
18년 전 조회 1,807
18년 전 조회 2,894
18년 전 조회 1,844
18년 전 조회 2,888
18년 전 조회 2,724
18년 전 조회 1,735
18년 전 조회 1,671
18년 전 조회 1,925
18년 전 조회 2,422
18년 전 조회 2,208
18년 전 조회 2,546
18년 전 조회 5,071
18년 전 조회 1,981
18년 전 조회 1,414
18년 전 조회 1,542
18년 전 조회 1,511
18년 전 조회 1,234
18년 전 조회 1,237
18년 전 조회 1,581
18년 전 조회 1,532
18년 전 조회 2,526
18년 전 조회 1,398
18년 전 조회 1,780
18년 전 조회 2,255
18년 전 조회 1,442
18년 전 조회 3,003
18년 전 조회 1,450
18년 전 조회 1,821
18년 전 조회 1,659
18년 전 조회 1,612
18년 전 조회 1,407
18년 전 조회 1,225
18년 전 조회 1,833
18년 전 조회 1,270
18년 전 조회 3,786
18년 전 조회 1,891
18년 전 조회 1,968
18년 전 조회 1,289
18년 전 조회 2,033
18년 전 조회 1,268
18년 전 조회 1,337
18년 전 조회 1,183
18년 전 조회 1,169
18년 전 조회 1,254
18년 전 조회 2,747
18년 전 조회 1,710
18년 전 조회 1,801
18년 전 조회 1,353
18년 전 조회 2,027
18년 전 조회 1,669
18년 전 조회 1,641
18년 전 조회 1,867