如何每10秒追加2个div?

时间:2019-04-30 18:04:32

标签: javascript jquery append settimeout intervals

我尝试使用protected void Page_Load(object sender, EventArgs e) { string connectionString; SqlConnection cnn; connectionString = @"Data Source=(LocalDb)\.;Initial Catalog=asp-Points;Integrated Security=True;AttachDBFilename=|DataDirectory|\Database1.mdf"; cnn = new SqlConnection(connectionString); cnn.Open(); SqlCommand command; SqlDataReader dataReader; string sql, Output = ""; sql = "Select [Point] from [dbo].[table]"; command = new SqlCommand(sql, cnn); dataReader = command.ExecuteReader(); // This logic to handle subtraction of data from database. while (dataReader.Read()) { int point = Convert.ToInt16(dataReader.GetValue(0)); if (prev != -1) { calcedPoint = point - prev; Output = Output + calcedPoint.ToString() + "</br>"; } prev = point; } Response.Write(Output); dataReader.Close(); command.Dispose(); cnn.Close(); } 每10秒显示一次跨度,但似乎没有生效。当前,即使没有10秒,跨度也会连续显示。如何解决?

setInterval
var i = 0;
var messages = {from: {type: "Other"}};
var myInterval = setInterval(function() {
  if (i === 2) return clearInterval(myInterval);
  if (messages.from.type === "Other") {
    $('.chat_converse').append("<span class='msg_item'>lorem ipsum</p></span>");
  }

  $('.chat_converse').append("<span class='msg_item2'>textextext</p></span>");
  i++;
}, 10000);

我需要期望的是每10秒显示2个跨度,并在每2个跨度之后显示附加的附录。

预期输出:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="chat_converse"></div>

0 个答案:

没有答案