php-綜合實作-開新視窗、頁面自動更新、取亂數值、動態更新表格背景顏色

在一個PHP檔案內(例如a.php)加入以下內容,會新增一個按鈕
<table width="650" height="30" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="right"><a href="#" onclick="window.open(' http://your_ip_or_domain//website/play_pop.php', '彈出新視窗', config='height=480,width=640');">彈出新視窗</a>&nbsp;</td>
  </tr>
</table>

另新增play_pop.php內容如下

<meta http-equiv="refresh" content="1" />

<?php
$x=rand();
$y=rand(0,$x);
$z=rand(0,$y);
$showstr=array("",base_convert($x, 10, 16));
$pmonthx=implode("#",$showstr);
$showstr=array("",base_convert($y, 10, 16));
$pmonthy=implode("#",$showstr);
$showstr=array("",base_convert($z, 10, 16));
$pmonthz=implode("#",$showstr);
echo $x;echo $pmonthx;echo $pmonthy;echo $pmonthz;?>
<table bgcolor="black" cellpadding="5" border="0">
<tr>
<td bgcolor="<?php echo $pmonthx;?>">表格欄位背景變化1</td>
<td bgcolor="<?php echo $pmonthy;?>">表格欄位背景變化2</td>
<td bgcolor="<?php echo $pmonthz;?>">表格欄位背景變化3</td>
</tr>
</table>

在a.php執行後點選「彈出新視窗」按鈕
就會彈出一個640*480的新視窗
然後每一秒會更新一次畫面
同時每一秒取亂數值
再把亂數值轉成16進位
再用字串函數將16進位改成#開頭的16進位
再將這#開頭的16進位填入表格內
這樣就會每一秒就會自斷更換不同的顏色

相關文章