2014-09-05 61 views
0

HTML如何使用jQuery追加一个div的点击功能?

<body> 
<input type="button" value="ADD" class="add"> 
    <div class="cont"> 
     <div class="wrapper"> 
     <input type="text" class="txt1"> 
     <input type="text" class="txt2">    
     <input type="button" value="Delete" class="del"> 
     </div> 
    </div> 
</body> 

SCRIPT

这里,如果我点击添加按钮全div有追加
$(document).ready(function(e) { 
    $(".add").on('click',function(){ 
     $(".cont").append$(".wrapper"); 
    }); 
}); 

嗨frnds我。我不知道我是否正确。请指导我。

+2

'$(”续“).append($(”)包装“);' – 2014-09-05 06:03:10

回答

1

append$()不是jQuery函数

Chagne

$(".cont").append$(".wrapper"); 

$(".cont").append($(".wrapper")); 

OR

$(".wrapper").appendTo(".count") 
1
$(document).ready(function(e) { 
    $(".add").on('click',function(){ 
    var item = $(".wrapper").eq(0).clone(); 
    $(".cont").after(item); 
    }); 
}); 

编辑: -

小提琴链接: - http://jsfiddle.net/cj575cey/1/

+0

喜抛出你的代码是当过我点击它越来越一倍。 – 2014-09-05 06:09:07

+0

@manojistack尝试'$( “包装”)。EQ(0).clone()' – 2014-09-05 06:10:23

+0

http://jsfiddle.net/pranavcbalan/5L3uwjr8/ – 2014-09-05 06:11:59

1

.wrapper已经被.cont包裹。

$(document).ready(function(e) { 
$(".add").on('click',function(){ 
    $(".cont").append($(".wrapper"));//change append$(".wrapper") to .append($(".wrapper")) 
    }); 
});