【问题标题】:Random Image as link associated with image随机图像作为与图像关联的链接
【发布时间】:2010-09-18 19:38:39
【问题描述】:

我正在寻找一个脚本,该脚本将在页面加载时调用链接到其相应网站的随机图像。任何人都知道一个javascript或php的方式来做到这一点?

【问题讨论】:

    标签: scripting random


    【解决方案1】:
    <?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";
    
    ?>
    

    快速简单。可能不是最好的方法 - 我会亲自将它连接到数据库而不是静态数组 - 但它会让你在几秒钟内启动并运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-24
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      • 2019-04-26
      • 2011-01-11
      • 1970-01-01
      相关资源
      最近更新 更多