我在按钮点击时添加了一个div,我希望用户能够通过单击“X”(一个锚点)来从列表中删除已添加的项目,但是单击事件没有触发。这是我的代码,我甚至尝试过绑定,但似乎都不起作用。
(function ( $ ) {
$(document).ready(function(){
$(".btn-add").on("click",function() {
var $row = $(this).closest("tr"); // Find the row
var $text = $row.find(".this-name").text(); // Find the text
// Let's test it out
$('#col2').append('<div class="item"><p>'+$text+'</p><a href="#" class="delete-button">X</a></div>');
});
});
$("document").on('click','.delete-button', function(e){
e.preventDefault();
alert('yes');
$(this).closest('.item').remove();
});
}( jQuery ));
非常感谢,欢迎提供任何帮助。
document
,不是"document"
。 - Ameya Deshpandehtml
代码,以便我们可以复制这个。 - Guruprasad J Rao