0

注意:单击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];
} 
?>
4

1 回答 1

3

Empty 只判断一个变量是否为空,使用 unset。

if ($_GET['clear']=="1") {unset($_SESSION['choice_1']);}
于 2012-11-05T05:20:04.607 回答