我有这个功能:
$('#addNote').click(function() {
var html =
'<div class="row-fluid" id="notenote"><div class="span9">' +
$('#noteContent').val() +
'<input type="hidden" value="' + $('#noteContent').val() + '" name=notes[]>' +
'</div>' +
'<div class="span3 ">' +
'<img width="68" height="60" src="getimage.php?image=current_admin">' +
'<div class="pull-right">' +
' ' +
'<a href="javascript:void(0)" class="removeNote"><i class="icon-remove"></i></a>' +
' ' +
'</div>' +
'</div>' +
'</div>';
if ($('#noteContent').val() !== '') {
$('#noteContent').val('');
var newnote = $("#noteContainer").append(html);
newnote.find('.removeNote').on("click", function(event) {
event.preventDefault();
newnote.remove();
});
}
});
问题是,当newnote.remove()
被触发时,它也会删除主容器 DIV #noteContainer
,而它应该只删除自己,所以 DIV#notenote
并没有别的。如何修复此代码?
谢谢