삭제 양식 동적 추가

<form action="testlist.action" method="post">
    <table id="myTable">
        <tr>
            <td> <input type="text" name="list[0].username"/></td>
            <td> <input type="text" name="list[0].password" /></td>
        </tr>
    </table>
    <input type="button" value=" " id="newBtn" /> <input type="button"
        value=" " id="delBtn" /> <input type="submit" value=" "
        id="submitBtn" />
</form>
<script src="../js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
    var i = 0;
    $(document)
            .ready(
                    function() {
                        $("#newBtn")
                                .bind(
                                        "click",
                                        function() {
                                            i++;
                                            //alert(i);
                                            //alert($("input:checked"));
                                            $("#myTable")
                                                    .append(
                                                            "<tr><td> <input type=\"text\" name=\"list["+i+"].username\"/></td></td><td> <input type=\"text\" name=\"list["+i+"].password\"/></td></tr>");
                                            // alert(document.getElementById('sd').value);
                                        });
                        $("#delBtn").bind(
                                "click",
                                function() {
                                    //alert(" "+i);
                                    //alert($("input:checked"));
                                    //$("input:checked").parent().parent().remove();
                                    //$("#myTable").remove();
                                    //alert($("#myTable input[name=aa]").val());
                                    //$("table").remove(tag);
                                    $(
                                            "#myTable input[name='list[" + i
                                                    + "].username']").parent()
                                            .parent().remove();
                                    if (i >= 0)
                                        i--;
                                });
                    });
</script>

백그라운드 수신 매개 변수
List<User> list = null;
    public List<User> getList() {
        return list;
    }
    public void setList(List<User> list) {
        this.list = list;
    }
        if (list != null && !list.equals("")) {
            for (Iterator<User> iterator = list.iterator(); iterator
                    .hasNext();) {
                User user = (User) iterator.next();
                System.out.println(user.getUsername() + " " + user.getPassword());
            }
        }

좋은 웹페이지 즐겨찾기