简体   繁体   English

每次插入循环后如何断开div

[英]How I can break the div after each loop of insertion

Actually each time I press the button it should show some thing like in facebook chat box to show new message but instead on each click the new message does not go in the downward but instead it comes next to it. 实际上,每次我按下按钮时,它都应该在Facebook聊天框中显示一些内容,以显示新消息,但是每次单击时,新消息都不会向下显示,而是紧随其后。

<script>
$(document).ready(function() {
    $('#im_chat').click(function() {
        var a = $('#im_textarea').val();

        alert("It is working!!!!");
        $('#im_popup')
            .append($('<p CLASS="well well-sm" id="msg"></p>')
            .css('margin', '10px')
            .css('display', 'inline-block')
            .text(a));
    })
})
</script>

图片

Don't use display: inline-block; 不要使用display: inline-block; , just show each message in a <div> or any other element displayed as a block : ,只需将每个消息显示在<div>或任何其他显示为块的元素中:

 $(document).ready(function() { $('#im_chat').click(function() { var a = $('#im_textarea').val(); var $message = $('<div />') .css({ margin: '10px' }) .text(a); $('#im_popup').append($message) }) }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="im_popup"></div> <textarea id="im_textarea"></textarea> <div> <button id="im_chat">Send</button> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM