在javascript中创建stringbuilder类型功能以显示聊天消息
dt_msg是一个数据表,其中我有一些聊天信息,通过发送和发送。 我使用stringbuilder将这些消息显示在屏幕上,如下所示在javascript中创建stringbuilder类型功能以显示聊天消息,javascript,asp.net,ajax,html,asp.net-ajax,Javascript,Asp.net,Ajax,Html,Asp.net Ajax,dt_msg是一个数据表,其中我有一些聊天信息,通过发送和发送。 我使用stringbuilder将这些消息显示在屏幕上,如下所示 stringBuilder1.Append("<div style='background-color:ALICEBLUE;float:left; width:100%; word-wrap: break-word;font-size:14px;'><pre><font color='Red'><b><div s
stringBuilder1.Append("<div style='background-color:ALICEBLUE;float:left; width:100%; word-wrap: break-word;font-size:14px;'><pre><font color='Red'><b><div style='background-color:ALICEBLUE;word-wrap: break-word; margin-right:410px;'>" + dt_msg.Rows[i][2].ToString() + " Says: </b></font></pre></div><div style='background-color:ALICEBLUE;font-size:14px;float: left;width: 410px;margin-left: -410px; word-wrap: break-word;font-size:14px;'><pre><font>" + dt_msg.Rows[i][0].ToString() + "</font></pre></div><div style='background-color:ALICEBLUE; word-wrap: break-word;'><p style='color:#8B8A8A; margin-top:0'>Sent at " + Convert.ToDateTime(dt_msg.Rows[i][1]).ToLongTimeString() + "</p></div><div style='clear:both;'></div>")
它是用ajax代码接收的
var data = 'User1 says :~Hello to this world and enjoy this week~sent at 05:40:30 AM@#User2 says :~Hello to my world~sent at 05:41:35 AM';
var ul = document.getElementById('your_ul');
data.split('@#').forEach(function(d) {
var li = document.createElement('li');
li.innerHTML = d;
ul.appendChild(li);
});
但我想像在上一页中使用stringBuilder一样显示消息。如何显示使用stringBuilder显示的字符串。这里的字符串@#是行分隔符A
StringBuilder
构造是不需要的。如果您为此创建了适当的结构,请使用无序列表(ul
->所有消息),并不断向其中添加列表项(li
->每条消息)
请注意,以上未经测试更换
与
User1说:~Hello to this world and like this week~发送时间为上午5:40:30@#User2说:~Hello to my world~发送时间为上午5:41:35
如何使用javascript以最佳方式显示此内容
<script type="text/javascript">
function OnSuccess(data) {
if (data.d)
{
div1.innerText = data.d;
}
}
</script>
User1 says :~Hello to this world and enjoy this week~sent at 05:40:30 AM@#User2 says :~Hello to my world~sent at 05:41:35 AM;
var data = 'User1 says :~Hello to this world and enjoy this week~sent at 05:40:30 AM@#User2 says :~Hello to my world~sent at 05:41:35 AM';
var ul = document.getElementById('your_ul');
data.split('@#').forEach(function(d) {
var li = document.createElement('li');
li.innerHTML = d;
ul.appendChild(li);
});
div1.innerText = data.d;
div1.innerText = div1.innerText + data.d;