2015-02-24 67 views

回答

1

您在http://agentboris.com/newwebsite/index.html的文件位於.html,它應該在.php中,因爲您可以使用教程中的php代碼。

這個簡單的代碼嘗試(不要忘記保存您的索引文件作爲PHP擴展):

<?php 
    $bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg', 'bg-06.jpg', 'bg-07.jpg'); // array of filenames 

    $i = rand(0, count($bg)-1); // generate random number size of the array 
    $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen 
?> 


<!DOCTYPE html> 
<html> 
    <head> 
     <title>Tests purposes</title> 
     <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> 
     <style type="text/css"> 
     <!-- 
     body{ 
     background: url(images/<?php echo $selectedBg; ?>) no-repeat; 
     } 
     --> 
     </style> 
    </head> 

    <body> 


    </body> 
</html> 
+0

工作就像一個魅力,非常感謝! – 2015-02-24 15:58:06

+0

您的歡迎:) – lmarcelocc 2015-02-24 15:58:28