我正在尝试构建一个每个条目都有一个删除按钮的表,但输出让我感到困惑。代码如下:
if ($players != null) {
echo('<table class="playerTable">');
echo('<thead>');
echo('<tr>');
echo('<th> Last Name </th>');
echo('<th> First Name </th>');
echo('<th></th>');
echo('<th></th>');
echo('</tr></thead><tbody>');
for ($i=0; $i<count($players); $i++) {
printf('<form action="player.php" method="post" onSubmit="return submitCheck(\'%s\', \'%s\')">', $players[$i]->name, $players[$i]->surname);
echo("<tr>");
printf("<td> %s </td><td> %s </td>", $players[$i]->surname, $players[$i]->name);
echo('<td><input type="hidden" name="delete" value="'. $players[$i]->id .'"></td>');
echo('<td><input type="submit" value="Delete"></td>');
echo("</tr>");
echo('</form');
}
echo('</tbody></table>');
}
由于某种我不明白的原因,产生的输出如下:
<tbody>
<form action="player.php" method="post" onsubmit="return submitCheck('someName', 'someName')"></form>
<tr>
<td> someName </td>
<td> someName </td>
<td><input type="hidden" name="delete" value="1"></td>
<td><input type="submit" value="Delete">
</td>
</tr>
这当然导致了 submitCheck 不会被执行的事实——我在这里错过了什么?