旧行李 2014-11-10 12:06 采纳率: 25%
浏览 10

动态更改消息[关闭]

Closed. This question needs to be more focused. It is not currently accepting answers.
                </div>
            </div>
        </div>
                <hr class="my12 outline-none baw0 bb bc-powder-2">
            <div class="grid fw-nowrap fc-black-600">
                    <div class="grid--cell mr8">
                        <svg aria-hidden="true" class="svg-icon iconLightbulb" width="18" height="18" viewbox="0 0 18 18"><path d="M9.5.5a.5.5 0 0 0-1 0v.25a.5.5 0 0 0 1 0V.5zm5.6 2.1a.5.5 0 0 0-.7-.7l-.25.25a.5.5 0 0 0 .7.7l.25-.25zM1 7.5c0-.28.22-.5.5-.5H2a.5.5 0 0 1 0 1h-.5a.5.5 0 0 1-.5-.5zm14.5 0c0-.28.22-.5.5-.5h.5a.5.5 0 0 1 0 1H16a.5.5 0 0 1-.5-.5zM2.9 1.9c.2-.2.5-.2.7 0l.25.25a.5.5 0 1 1-.7.7L2.9 2.6a.5.5 0 0 1 0-.7z" fill-opacity=".4"></path><path opacity=".4" d="M7 16h4v1a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1v-1z" fill="#3F3F3F"></path><path d="M15 8a6 6 0 0 1-3.5 5.46V14a1 1 0 0 1-1 1h-3a1 1 0 0 1-1-1v-.54A6 6 0 1 1 15 8zm-4.15-3.85a.5.5 0 0 0-.7.7l2 2a.5.5 0 0 0 .7-.7l-2-2z" fill="#FFC166"></path></svg>
                    </div>
                <div class="grid--cell lh-md">
                    <p class="mb0">
                        <b>Want to improve this question?</b> Update the question so it focuses on one problem only by <a href="/posts/26843471/edit">editing this post</a>.
                    </p>
                    <p class="mb0 mt6">Closed <span title="2014-11-10 12:43:56Z" class="relativetime">5 years ago</span>.</p>
                </div>
            </div>
    </aside>

I have a php array.
I want to make a dynamic changing message (without reload a page) that will change every 10 seconds. For example:

arr[0] = "abc";

arr[1] = "def";

arr[2] = "ghi";

arr[3] = "jkl";

And I want to make a script using AJAX or jquery that prints different string in the array every 10 seconds (print in a div).
My knowledge in AJAX and jquery is very small and I have no idea where to start.

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33734785 2014-11-10 12:13
    关注

    Try this : You can use setInterval and set its iterval period to 10000 ms. select message from array and put it in div's html.

    var arr = {"abc","def","ghi","jkl"};
    $(function(){
      var i = 0;
      var len = arr.length;
      setInterval(function(){
       //assuming div1 is the id of div for message
       $('#div1').html(arr[i]);
       i++;
       //reset array index if last element accessed
       if(i==len)
          i = 0;
      }, 10000);
    }):
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法