我已经尝试过allthinng anmad无法让这个程序工作。这是一个国际象棋程序。当用户双击电路板上的方块时,应将单元格添加到move_to / move_from变量中的表单中。
以下是代码snippits:
<?php
$results = array(array("Br", "Bn", "Bb", "Bq", "Bk", "Bb", "Bn", "Br"),array("Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp"),
array("", "", "", "", "", "", "", ""),array("", "", "", "", "", "", "", ""),array("", "", "", "", "", "", "", ""),
array("", "", "", "", "", "", "", ""),array("Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp"),
array("Wr", "Wn", "Wb", "Wq", "Wk", "Wb", "Wn", "Wr"));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Jquery Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="jq.css" rel="stylesheet" />
<link type="text/css" href="jquery-ui-1.8.9.custom.css" rel="stylesheet" />
</head>
<!-- Uses Session Variables -->
<body>
<div id="main">
<fieldset id="main_fieldset">
<table cellspacing="100">
<tbody >
<tr>
<td class="b1">8</td><td class="d1" id="a8"><?php echo $results[0][0];?> </td><td class="a1" id="b8" ><?php echo $results[0][1];?>
</td><td class="d1" id="c8"> <?php echo $results[0][2];?> </td><td class="a1" id="d8">
<?php echo $results[0][3];?> </td><td class="d1" id="e8"><?php echo $results[0][4];?> </td><td class="a1" id="f8">
<?php echo $results[0][5];?> </td>
<td class="d1" id="g8"> <?php echo $results[0][6];?> </td><td class="a1" id="h8"> <?php echo $results[0][7];?> </td>
</tr>
剪断..
<script type="text/javascript">
$(document).ready(function(){
$('.a1').click(function() {
$(this).css("background-color","grey");
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$('.a1').dblclick(function() {
$(this).css("background-color","blue");
move_from = $(this).attr("id");
$.post('jq_test.php',move_from);
alert(move_from);
});
});
<p><a href="jq_test.php?move_from">x</a></p>
<?php
echo "this is the variable ";echo $_GET['move_from'];
print_r($_GET);
?>
...剪断
<?php
echo <<<HTML
<form method="post" action="jq_test.php">
Move From<input type="text" name="move_from"> </input><br /><br />
Move To <input type="text" name="move_to"></input><br /><br />
<input type="submit" value="Enter Move"></input>
</form>
HTML;
?>
</body>
</html>
答案 0 :(得分:3)
您的javascript正在使用$.post()
,但您正在使用PHP中的$_GET
进行检索。切换到PHP中的$_POST
。