每x秒重新加载随机div内容 [英] Reload random div content every x seconds

查看:106
本文介绍了每x秒重新加载随机div内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,随机显示每个页面上的10个文件中的1个文件。我希望在8秒钟的时间间隔内重新加载,给我一个不同的10个文件中的每一个重新加载。



我读了一些使用jQuery .load 作为解决方案的相关问题,但是这并不适合我的代码,因为我没有每次加载特定文件。



这是我的div内容:

 < div id =tall-content > 

<?

$ random = rand(1,10);

包含'tall-files /'。 $随机。 .PHP;

?>

< / div>

谢谢

解决方案使用PHP来完成这是不切实际的。这个例子使用jQuery和PHP。

  $(document).ready(function(){
$(# (random.php);
var refreshId = setInterval(function(){
$(#div)。load('random.php');
},8000);
$ .ajaxSetup({cache:false});
});

random.php

  $ pages = array(page1.php,page2.php,page3.php,page4.php,page5.php); 

$ randompage = $ pages [mt_rand(0,count($ pages)-1)];

包括($ randompage);


I've got a div that randomly shows 1 of 10 files on each pageload. I'd like this to reload on a set time interval of 8 seconds, giving me a different one of the 10 files each reload.

I've read a few of the related questions using jQuery .load as a solution but this doesn't quite work with my code since I'm not loading a specific file each time.

This is my div content:

<div id="tall-content">

 <?

  $random = rand(1,10);

  include 'tall-files/' . $random . '.php';

 ?>

</div>

Thanks

解决方案

Using only PHP to accomplish this is impractical. This example uses jQuery and PHP.

$(document).ready(function() {
     $("#div").load("random.php");
     var refreshId = setInterval(function() {
         $("#div").load('random.php');
     }, 8000);
     $.ajaxSetup({ cache: false });
});

random.php

$pages = array("page1.php", "page2.php", "page3.php", "page4.php", "page5.php");

$randompage = $pages[mt_rand(0, count($pages) -1)];

include ($randompage);

这篇关于每x秒重新加载随机div内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆