大家好,我用PHP动态生成四个FORM,每个FORM都有两个隐藏值,我怎么可以在JS里得到该隐藏值比如PID的值?
<html>
<head>
<style>
img {border:0px;}
</style>
<script type="text/javascript">function addtocart()
{
var mesg = document.getElementById("msg"); var id = document.addcart.pid.value;
alert(id);
}
</script> </head>
<body><table>
<tr>
<td><table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965375.jpg" />
</td>
<td>New Casing<br/>Price: 300<br/>Promotion Price: 100<br/>
<input type="hidden" name="pid" value="11">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
</body>
</html>
<html>
<head>
<style>
img {border:0px;}
</style>
<script type="text/javascript">function addtocart()
{
var mesg = document.getElementById("msg"); var id = document.addcart.pid.value;
alert(id);
}
</script> </head>
<body><table>
<tr>
<td><table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965375.jpg" />
</td>
<td>New Casing<br/>Price: 300<br/>Promotion Price: 100<br/>
<input type="hidden" name="pid" value="11">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
</body>
</html>
<head>
<style>
img {border:0px;}
</style>
<script type="text/javascript">function addtocart()
{
var mesg = document.getElementById("msg"); var id = document.addcart.pid.value;
alert(id);
}
</script></head>
<body><table>
<tr>
<td><table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965375.jpg" />
</td>
<td>New Casing<br/>Price: 300<br/>Promotion Price: 100<br/>
<input type="hidden" name="pid" value="11">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<script type="text/javascript">
var ccc = document.forms["addcart"].pid.value;
alert(ccc);
</script>
</body>
</html>
<html>
<head>
<style>
img {border:0px;}
</style>
<script type="text/javascript">function addtocart()
{
var mesg = document.getElementById("msg"); var id = document.addcart.pid.value;
alert(id);
}
</script></head>
<body><table>
<tr>
<td><table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965375.jpg" />
</td>
<td>New Casing<br/>Price: 300<br/>Promotion Price: 100<br/>
<input type="hidden" name="pid" value="11">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<table>
<form name="addcart" method="POST" action="">
<tr>
<td>
<img src="uploads/thumb/1189965013.jpg" />
</td>
<td>2 u casing<br/>Price: 200<br/>Promotion Price: 30<br/>
<input type="hidden" name="pid" value="10">
<input type="image" src="images/order.jpg" name="submit" ONCLICK="addtocart()"/>
</td>
</tr>
</form>
</table>
<script type="text/javascript">
alert(document.forms[0].pid.value);
alert(document.forms[1].pid.value);
alert(document.forms[2].pid.value);
</script>
</body>
</ht
alert(document.forms[1].pid.value);
alert(document.forms[2].pid.value);
要那么form干嘛? 重新设计