juery实现多行添加,

来源:互联网 发布:傻妹妹雾化器完美数据 编辑:程序博客网 时间:2024/05/21 05:44
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>jQuery联系</title>
    <script src='./jquery-1.9.1.min.js'></script>
</head>
<center>
   <tr>
    <td>ID</td>
    <td>姓名</td>
    <td>职位</td>
    <td>薪水</td>
   </tr>
   <div >
  <table border=1>
   <tr>
    <td>1</td>
    <td>张三</td>
    <td>前端</td>
    <td>13k</td>
   </tr>
    </table>
    <input type='button' value='+增加一行' class='but'>
</div>
</body>
<script>
    $(function(){
        $('.but').click(function(){
            $('div:first').clone(true).insertAfter('div:last').append("<input type='button' value='-' class='del'>");
            $('.del').click(function(){
                $(this).parent().remove();
            })
        })
    })

</script>


juery批量添加表单

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="./jquery-1.9.1.min.js"></script>
</head>
<body>
<p id="bb"><input type="text"/></p>
<input type="button"value="点击" class="aa"/>
</body>
</html>
<script>
    $(function(){
        $('.aa').click(function(){
           var html='<p id="bb"><input type="text"/><span onclick="fun(this)"><button>删除</button></span></p>';
            $('#bb').after(html);
        })
//        $('.ss').click(function(){
//            $(this).parent().remove();
//        })
   })
    function fun(ts){
        $(ts).parent().remove();
    }
</script>


<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<script src="./jquery-1.9.1.min.js"></script>
<body>
     <p id="c">文件<input type="text"/><button name="add">添加</button></p>
</body>
</html>
<script>
    $(document).on('click','button[name="add"]',function(){
        $("#c").after("<p>文件<input type='text'/><button name='add'>添加</button><button name='del'>删除</button></p>");
    });

    $(document).on('click','button[name="del"]',function(){
        var del = $(this).parent();
        del.remove();
    });


</script>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>jQuery联系</title>
    <script src='./jquery-1.9.1.min.js'></script>
</head>
<body>
<div id='d2'>
    <input type='file'>
    <input type='button' value='添加' class='but'>
</div>
</body>
<script>
    $(function(){
        $('.but').click(function(){
            $('div:first').clone(true).insertAfter('div:last').append("<input type='button' value='删除' class='del'>");
            $('.del').click(function(){
                $(this).parent().remove();
            })
        })
    })
</script>
</html>


0 0
原创粉丝点击