[英]jquery - append html doesn't append the empty String inside the div
I am doing a chat project
in java
. 我正在用
java
做一个chat project
。
Using my Server response
through jquery-ajax
, I am creating an html
and append
the html to div
. 使用通过
jquery-ajax
Server response
,我正在创建一个html
append
该html append
到div
。
My jquery - html
alert without empty string
-name(note the id='user'
in the alert) will be , 我的
jquery - html
警报without empty string
-name(请注意警报中的id='user'
)将为,
after appending
this in the chat area
, after appending
到chat area
,
After jquery-html
alert with empty string
-name(note the id='user'
in the alert) will be , 在
with empty string
-name(请注意警报中的id='user'
)的jquery-html
警报后,
after appending
this in the chat area
, after appending
到chat area
,
My jquery for creating the HTML will be , 我创建HTML的jquery是,
function send(name , message , time){
//name = $("#name").val();
//message = $("#message").val();
var user = "<div id='user' class='fontStyle'>"+name+"</div>";
var msg = "<div id='msg' class='fontStyle'>"+message+"</div>";
var timeStamp = "<div id='time' class='fontStyle'>"+time+"</div>";
var row = "<div id='msgSet' >"+ user + msg + timeStamp +"</div>";
alert(row);
return row;
}
There is no empty string will be present in chat area
. chat area
中将没有空字符串。
Hope our stack members will help me. 希望我们的堆栈成员能帮助我。
You can escape html your string so it keeps the white spaces. 您可以转义html字符串,以保留空格。 See details here .
在这里查看详细信息。
Or you can trim your message string (=remove spaces at the beginning and end of it) with such an instruction, and then manualy add the spaces (with the
code inside a div, span, ...): 或者,您可以使用这样的指令来修剪消息字符串(=删除其开头和结尾处的空格),然后手动添加空格(在div,span等中间添加
代码):
s.replace(/\s+/g, ' ');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.