我有一个很小的问题。我有一个输入字段,其中有一个按钮,可以在单击时创建它的实例。启动单击事件时一切正常,但是当我针对生成的元素时出现问题after()
,我似乎无法做到这一点。请看下面的代码
HTML
<div class="after-add-more form-group">
<input type="text" name="addmore[]" class="form-control" placeholder="Enter Something here">
</div>
<!-- Copy Fields -->
<div class="copy hide">
<div class="form-group more-duty">
<input type="text" name="addmore[]" class="form-control try" placeholder="Enter More stuffs here">
<button class="remove" type="button">Remove Stuff</button>
</div>
</div>
<button class="add-more" type="button">Add Stuff</button>
Javascript
$(".add-more").click(function(){
var html = $(".copy").html();
$(".after-add-more").after(html);
});
$("body").on("click",".remove",function(){
$(this).parents(".more-duty").remove();
});
$('.try').click(function() {
alert("Ouch");
});
当我单击生成的输入以便我可以回显 ouch 时,不会调用该事件。请看这个小提琴。任何帮助将不胜感激 。谢谢 。