jq动态增加,减少input表单

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <form action="" method="get" class="form">
        <div class="inputGroup">
            <input type="text" name="">
            <span class="btnDel">删除</span>
        </div>
        <span class="btnAdd">新增</span>
        <button type="submit">提交</button>
    </form>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script>
        $(function () {
            $('form').on('click', '.btnDel', function () {
                $(this).parent().remove();
            });
            $('.btnAdd').click(function () {
                var str = '<div class="inputGroup">' +
                '            <input type="text" name="name">' +
                '            <span class="btnDel">删除</span>' +
                '        </div>';
                $('.btnAdd').before(str);
            });
        })
    </script>
</body>
</html>
赞赏

微信赞赏支付宝赞赏

236 次阅读量

发表评论