我目前正在制作一个想法白板,但似乎每当我尝试删除评论时,想法之间都会留下空白。
例如,如果我有以下评论:
但是当我删除一些东西时:
我将如何做到这一点,以便评论之间不留空隙?
到目前为止,这是我的代码:
jQuery(function ($) {
$('#chat').on('click', '.delete', function(e) {
$(this).parent().remove();
});
var socket = io.connect();
var $messageForm = $('#sendmessage');
var $messageTitle = $('#title');
var $messageBox = $('#message');
var $chat = $('#chat');
$messageForm.click(function (e) {
if ($.trim($("#title").val()).length === 0) {
alert('You must provide valid input');
$messageTitle.val('');
$messageBox.val('');
return false;
}
if ($.trim($("#message").val()).length === 0) {
alert('You must provide valid input');
$messageTitle.val('');
$messageBox.val('');
return false;
} else {
e.preventDefault();
socket.emit('send message', '<span class="idea"><b>' + $messageTitle.val() + '</b>' + ' - ' + $messageBox.val() + ' ' + '[' + '<a class="delete" href="#">Delete</a>' + ']</span>');
$messageTitle.val('');
$messageBox.val('');
}
});
socket.on('new message', function (data) {
$chat.prepend(data + "<br/>");
});
});
剩下的 HTML:
<div id="chat"><span class="idea"><b>sfdf</b> - czxczxc [<a class="delete" href="#">Delete</a>]</span>
<br><span class="idea"><b>dsdfsd</b> - sdfsdfsdf [<a class="delete" href="#">Delete</a>]</span>
<br>
<br><span class="idea"><b>dsfsdf</b> - sdfsdf [<a class="delete" href="#">Delete</a>]</span>
<br>
</div>