为啥所有按钮只控制同一行数据???
为啥所有按钮只控制同一行数据?应该怎么解决啊。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="javascript" type="text/javascript">
function showtd(num) {
document.getElementById("bg"+num).style.display = "none";
document.getElementById("show"+num).style.display = "block";
document.getElementById("ba"+num);
document.getElementById("gn"+num);
}
function hidetd(num) {
document.getElementById("bg"+num).style.display = 'block';
document.getElementById("show"+num).style.display = 'none';
}
function showtext(){
document.getElementById("a").removeAttribute("readOnly");
document.getElementById("b").removeAttribute("readOnly");
document.getElementById("c").removeAttribute("readOnly");
document.getElementById("d").removeAttribute("readOnly");
document.getElementById("e").removeAttribute("readOnly");
document.getElementById("f").removeAttribute("readOnly");
}
function hidetext(){
document.getElementById("a").readOnly="true";
document.getElementById("b").readOnly="true";
document.getElementById("c").readOnly="true";
document.getElementById("d").readOnly="true";
document.getElementById("e").readOnly="true";
document.getElementById("f").readOnly="true";
}
</script>
</head>
<body>
<form>
<table border="1">
<?php
$db = mysql_connect('localhost','root','root');
mysql_select_db('ec',$db);
if (!$db)
{
die('Could not connect: ' . mysql_error());
}
$result = mysql_query("select * from goods");
echo "<tr>
<th>GoodsID</th>
<th>BarCode</th>
<th>GoodsName</th>
<th>Category</th>
<th>Specifications</th>
<th>Manufacturers</th>
<th>Numbers</th>
<th>Instructions</th>
<th>Pictures</th>
<th>Update</th>
<th>Delete</th>
</tr>";
$n = 0;
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . "<input type='text' id='a' value='$row[barcode]' style='width:60px;border:0px' readOnly>" . "</td>";
echo "<td>" . "<input type='text' id='b' value='$row[goods_name]' style='width:90px;border:0px' readOnly>" . "</td>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . "<input type='text' id='c' value='$row[specifications]' style='width:90px;border:0px' readOnly>" . "</td>";
echo "<td>" . "<input type='text' id='d' value='$row[manufacturers]' style='width:90px;border:0px' readOnly>" . "</td>";
echo "<td>" . "<input type='text' id='e' value='$row[number]' style='width:60px;border:0px' readOnly>" . "</td>";
echo "<td>" . "<input type='text' id='f' value='$row[instruction]' style='width:80px;border:0px' readOnly>" . "</td>";
echo "<td>" . "<img src = '$row[picture_url]' style='width:80px;height=60px'/>" . "</td>";
echo "<td id='bg$n'>".
"<input id='btnshow$n' type='button' value='Update' onclick='showtd($n);showtext()' />".
"</td>".
"<td id='show$n' style='display:none'>".
"<input id='btnclose$n' type='button' value='Save' onclick='hidetd($n);hidetext()'/>".
"</td>";
echo "<td>"."<a href='delete.php?id=$row[id]'>"."Delete"."</a>"."</td>";
echo "</tr>";
++$n;
}
mysql_close($db);
?>
</table>
</form>
</body>
</html>