리자

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

· 2007-05-08 (화) 09:37:31 · 3885
<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에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
12-01-11 조회 2,755
12-01-11 조회 1.2만
12-01-10 조회 2,854
12-01-08 조회 3,445
12-01-05 조회 5,337
11-12-29 조회 3,054
11-12-27 조회 2,839
11-12-25 조회 3,023
11-12-22 조회 3,457
11-12-14 조회 2,921
11-12-12 조회 3,542
11-11-28 조회 3,377
10-10-19 조회 2,837
08-09-05 조회 3,756
08-09-05 조회 3,572
08-06-14 조회 3,315
08-04-22 조회 3,593
08-04-17 조회 3,600
07-10-03 조회 4,213
07-10-03 조회 3,609
07-10-03 조회 7,293
07-10-03 조회 4,569
07-10-03 조회 3,265
07-10-03 조회 2,858
07-10-02 조회 3,571
07-10-02 조회 3,101
07-09-27 조회 5,022
07-09-27 조회 3,847
06-09-26 조회 3,516
06-09-26 조회 4,733
06-09-22 조회 3,908
06-09-22 조회 3,524
06-09-22 조회 4,269
06-09-21 조회 4,204
06-08-18 조회 3,696
05-11-30 조회 4,746
05-07-15 조회 4,592
05-03-23 조회 4,655
05-03-14 조회 3,323
05-03-13 조회 2,697
04-08-05 조회 5,771