【发布时间】:2012-11-05 05:14:57
【问题描述】:
注意:单击http://communitychessclub.com/rabren/index.php?clear=1 的左侧棋子应该会取消设置 $choice 并重新加载页面。但它只是重新加载页面。
我想检查在 javascript 中设置的变量状态。
onclick="window.location='index.php?clear=1'
和if clear == "1" 我想用:
$choice_1
if ($_GET['clear']=="1") {empty($_SESSION['choice_1']);}
并重建数组并生成新的图像引用。
但我所拥有的不起作用;它永远不会重置或清空$choice_1
我有一张带有主页链接的图片:
<img onclick="window.location='index.php?clear=1'; return false;"
src="images/WL<?php echo $_SESSION['choice_1'];?>.png" alt="pieces" width=128 height=128>
我在 index.php 的顶部:
图像集:
<?php
if ($_GET['clear']=="1") {empty($_SESSION['choice_1']);}
if(!isset($_SESSION['choice_1'])) {
$chessmen = array("N","Q","R","B","K","P");
$random_piece = array_rand($chessmen);
$_SESSION['choice_1'] = $chessmen[$random_piece];
unset($chessmen[$random_piece]);
$random_piece = array_rand($chessmen);
$_SESSION['choice_2'] = $chessmen[$random_piece];
}
?>
【问题讨论】: