我得到了几分钟前写的代码我想知道为什么不会删除该项目。jQuery列表项删除
(function($) {
$('#btn1').click(function() {
var textVal = $('#input').val();
if (textVal != "") {
$('#list').append('<li class="class1" id="' + textVal + '">' + textVal + '<input type="hidden" name="Tags" value="' + textVal + '" /> <input type="button" class="remove-item" value="X"></input></li> ');
}
});
$('.remove-item').click(function() {
$('.list #' + textVal).remove()
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="input" type="text" />
<input type="button" id="btn1" value="Add" />
<ul id="list"></ul>
你需要的事件代表团在这里! –