juery动态添加和删除

拼语句添加框(不能删除原有的tr)

//点击a标签
        $("#a").on("click",function(){
            var $newtr = $("<tr  id='model'>"  
                        +"<td><input type='text' name='contacts.contactName' value=''></td>"  
                        +"<td><input type='text' name='contacts.contactTel' value=''></td>"  
                        +"<td><input type='text' name='contacts.contactFax' value=''></td>"  
                        +"<td><input type='text' name='contacts.contactEmail' value=''></td>" 
                        +"<td><input type='text' name='contacts.contactRole' value=''></td>"
                        +"<td ><a href='javascript:void(0);' class='del'>删除</a></td>"
                        +"</tr>");
            $newtr.find(".del").click(function(){
                $(this).parents("tr").remove();
            });
            $("#fourdiv").append($newtr);            
        });

删除之前有的tr

$(".del").click(function(){
            $(this).parents("tr").remove();
        });    

效果图

posted @ 2015-12-17 15:17  夏末、初秋  阅读(170)  评论(0编辑  收藏  举报