【发布时间】:2010-09-18 19:38:39
【问题描述】:
我正在寻找一个脚本,该脚本将在页面加载时调用链接到其相应网站的随机图像。任何人都知道一个javascript或php的方式来做到这一点?
【问题讨论】:
我正在寻找一个脚本,该脚本将在页面加载时调用链接到其相应网站的随机图像。任何人都知道一个javascript或php的方式来做到这一点?
【问题讨论】:
<?php
$random = array(
array('image' => 'http://example.com/image1.jpg', 'url' => 'http://example1.com/'),
array('image' => 'http://example.com/image2.jpg', 'url' => 'http://example2.com/'),
array('image' => 'http://example.com/image3.jpg', 'url' => 'http://example3.com/'),
array('image' => 'http://example.com/image4.jpg', 'url' => 'http://example4.com/'),
);
$current = rand(0, count($random) - 1);
print "<a href=\"" . $random[$current]['url'] . "\"><img src=\"" . $random[$current]['image'] . "\" alt=\"\" /></a>\n";
?>
快速简单。可能不是最好的方法 - 我会亲自将它连接到数据库而不是静态数组 - 但它会让你在几秒钟内启动并运行。
【讨论】: