리자

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

· 18년 전 · 3048
<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년 전 조회 3,161
18년 전 조회 2,475
18년 전 조회 2,661
18년 전 조회 3,205
18년 전 조회 3,286
18년 전 조회 4,463
18년 전 조회 6,437
18년 전 조회 2,403
18년 전 조회 2,508
18년 전 조회 2,213
18년 전 조회 1,961
18년 전 조회 2,942
18년 전 조회 1,998
18년 전 조회 1,868
18년 전 조회 5,065
18년 전 조회 2,117
18년 전 조회 2,151
18년 전 조회 2,160
18년 전 조회 2,286
18년 전 조회 3,956
18년 전 조회 1,971
18년 전 조회 1,841
18년 전 조회 1,666
18년 전 조회 2,170
18년 전 조회 2,204
18년 전 조회 3,985
18년 전 조회 2,304
18년 전 조회 3,460
18년 전 조회 5,076
18년 전 조회 3,207
18년 전 조회 8,393
18년 전 조회 4,394
18년 전 조회 3,090
18년 전 조회 1,853
18년 전 조회 2,955
18년 전 조회 5,373
18년 전 조회 5,539
18년 전 조회 2,412
18년 전 조회 4,675
18년 전 조회 4,444
18년 전 조회 4,476
18년 전 조회 2,607
18년 전 조회 4,529
18년 전 조회 2,499
18년 전 조회 3,617
18년 전 조회 5,256
18년 전 조회 2,287
18년 전 조회 3,736
18년 전 조회 1,960
18년 전 조회 3,049
18년 전 조회 2,015
18년 전 조회 3,035
18년 전 조회 2,868
18년 전 조회 1,889
18년 전 조회 1,841
18년 전 조회 2,071
18년 전 조회 2,581
18년 전 조회 2,372
18년 전 조회 2,726
18년 전 조회 5,242
18년 전 조회 2,141
18년 전 조회 1,568
18년 전 조회 1,699
18년 전 조회 1,658
18년 전 조회 1,393
18년 전 조회 1,388
18년 전 조회 1,735
18년 전 조회 1,674
18년 전 조회 2,675
18년 전 조회 1,556
18년 전 조회 1,931
18년 전 조회 2,418
18년 전 조회 1,596
18년 전 조회 3,164
18년 전 조회 1,604
18년 전 조회 1,998
18년 전 조회 1,838
18년 전 조회 1,770
18년 전 조회 1,569
18년 전 조회 1,412
18년 전 조회 2,027
18년 전 조회 1,433
18년 전 조회 3,978
18년 전 조회 2,053
18년 전 조회 2,136
18년 전 조회 1,459
18년 전 조회 2,202
18년 전 조회 1,443
18년 전 조회 1,502
18년 전 조회 1,338
18년 전 조회 1,331
18년 전 조회 1,408
18년 전 조회 2,921
18년 전 조회 1,877
18년 전 조회 1,972
18년 전 조회 1,524
18년 전 조회 2,203
18년 전 조회 1,854
18년 전 조회 1,826
18년 전 조회 2,028