0

我正在定制一个基于聊天的 Web 界面。我对所使用的标记的控制非常有限。

基本上,我想<span class="icon" />为每条聊天消息添加新元素。

<div id="chatLog">
<span class="msg agent">
  <strong>Agent Name</strong>
  Hi, how are you today? How can I help?
</span>
<span class="msg customer">
  <strong>Customer Name</strong>
  I'm fine thanks, please can you tell me more about the products you sell?
</span>
</div>

我想使用的 jquery 是这样的:

<script>
  jquery('.msg').append('<span class="icon" />');
</script>

所以我有

<div id="chatLog">
<span class="msg agent">
  <strong>Agent Name</strong>
  Hi, how are you today? How can I help?
  <span class="icon" />
</span>
<span class="msg customer">
  <strong>Customer Name</strong>
  I'm fine thanks, please can you tell me more about the products you sell?
  <span class="icon" />
</span>
<div id="chatLog">

随着越来越多的消息在代理和客户之间发送,标记将不断变化。如何确保所有聊天消息都附加span.msg了这个新元素?<span class="icon" />

<div id="chatLog">
<span class="msg agent"><strong>Agent Name</strong>Hi, how are you today? How can I help?</span>
<span class="msg customer"><strong>Customer Name</strong>I'm fine thanks, please can you tell me more about the products you sell?</span>
<span class="msg agent"><strong>Agent Name</strong>Yes certainly, any particular product?</span>
<span class="msg customer"><strong>Customer Name</strong>Product ISBN-123-456 please</span>
<div id="chatLog">
4

0 回答 0