使用jquery从表中删除当前行

时间:2018-02-01 04:55:35

标签: jquery asp.net-mvc

我想通过使用jquery单击按钮来删除表的当前行 我试过这个,请帮帮我。

<script>
    $(document).ready(function () {
        $("#medbtn").click(function () {
            var medicinelist = $("#medList").val();
            var selecttype = $("#TypeList").val();
            var qtyInput = $("#qty").val();
            var text = $("#medList").text();
            var data = '<tr> <td>' + text + ' </td> <td>' + selecttype + '</td> <td>' + qtyInput + '</td> <td><input type="button" value="X" id="remove"/></td> <input type="hidden" value=' + medicinelist + '/> </tr>';
            $('#listMedicine').append(data);

   i have tried this here, but not remove the row please help me thanks
            $("#remove").click(function () {
                $('data').remove();
            })
        });


            });
</script>

1 个答案:

答案 0 :(得分:0)

你应该这样做:

$("#listMedicine").on("click", ".remove", function () {
   $('data').remove();
});

因为#remove是动态创建的,而且DOM不会将点击处理程序附加到它。也使用类.remove,因为ID无法重复。