在我的网站上模拟聊天消息

时间:2014-04-05 11:11:33

标签: javascript html css ajax web

如何逐行显示文本,时间跨度为秒。
用户不应该回答。
我想模拟聊天消息。

1 个答案:

答案 0 :(得分:0)

FIDDLE会让你开始。

  1. 随机短语数组

  2. 一个定时器函数,它随机读取它们并将它们放在div中。

  3. JS

    var randomphrases = ['We the people','in order to form','a more perfect union','establish justice','insure domestic tranquility','provide for the common defence, promote the general welfare','and secure the blessings of liberty','to ourselves','and our posterity','do ordain and establish this constitution','of the United States of America'];
    
    var c = 0;
    var t;
    var timer_is_on = 0;
    
    timedCount();
    
    function timedCount()
    {
     t = setTimeout( function(){ timedCount() }, 1500 );
     random = Math.floor(Math.random() * (11 - 0 + 1)) + 0;
     $('.putmehere').html( randomphrases[random]);
    
    }