ダイナミックフォームの作成のCSS&HTML&JavaScript結合アプリケーション


需要:cssスタイルとHTML表とJavaScriptを結合して動的表を作成して、データを削除できます.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>    </title>
</head>

<style>
    table {
        border: 1px solid;
        margin: auto;
        width: 500px;
    }

    div {
        text-align: center;
        margin: 50px;
    }

    td, th {
        text-align: center;
        border: 1px solid;
    }

</style>

<body>


<div>
    <input type="text" id="id" placeholder="     ">
    <input type="text" id="name" placeholder="     ">
    <input type="text" id="gender" placeholder="     ">
    <input type="submit" value="  " id="btn_add">
</div>

<table>
    <caption>     </caption>
    <tr>
        <th>  </th>
        <th>  </th>
        <th>  </th>
        <th>  </th>
    </tr>
    <tr>
        <td>1</td>
        <td>  </td>
        <td> </td>
        <td><a href="javascript:void(0);" onclick="delTr(this)">  </a></td>
    </tr>
    <tr>
        <td>2</td>
        <td>  </td>
        <td> </td>
        <td><a href="javascript:void(0);" onclick="delTr(this)">  </a></td>
    </tr>

</table>
<script>


    document.getElementById("btn_add").onclick = function () {
        //       
        var id = document.getElementById("id").value;
        var name = document.getElementById("name").value;
        var gender = document.getElementById("gender").value;

        //  table
        var table = document.getElementsByTagName("table")[0];
        //    
        table.innerHTML += "
" + "" + id + "
" + "" + name + "
" + "" + gender + "
" + "
" + ""
}; // function delTr(obj) { var table = obj.parentNode.parentNode.parentNode; var tr = obj.parentNode.parentNode; table.removeChild(tr); } </script> </body> </html>