我有一个小问题,基本上我有一个隐藏的输入按钮,它是从数据库表中加载一个唯一值:<input type="hidden" name="ProductId" class="ProductId" value='.$row["ProductId"].' />
此按钮重复根据有多少行分配唯一的ID到<input>按钮,并阅读它使用jquery
while ($row = $result->fetch()) {
echo '<table class="cart-row" cellspacing="0" cellpadding="0" width="100%">';
echo '<tbody>';
echo '<tr>';
echo '<td width="75"><img border="0" width="59px" height="78px" title="" alt="" src=' . $row["ImagePath"] .'></td>';
echo '<td width="203"><span class="itemElements itemName">'. $row["Name"] .'</span></td>';
echo '<td width="203"><input type="submit" class="btnMinus linkbtnType2" value="-"><input type="submit" class="btnPlus linkbtnType2" value="+"></td>';
echo '<td width="135"><span class="qtyNum">('. $row["Qty"] .')</span> <br />';
echo '<input type="hidden" name="ProductId" class="ProductId" value='.$row["ProductId"].' />';
echo '<span class="qtyRemoveLink"><input type="submit" class="btnRemove linkbtn" value="Remove"></td>';
echo '<td width="180"><span class="itemElements orderStatus">In Stock Usually dispatched within 24 hours</span></td>';
echo '<td width="175" class="itemPriceRow"><span id="itemPrice">€ '. $row["Price"] .'</span></td>';
echo '</tr>';
echo '</tbody>';
echo '</table>';
echo '<br>';
}
im使用一个jQuery方法使用读取来自隐藏按钮但是它仅读取来自所产生的第一输入按键的值该值:通过该方法返回。我尝试将ID从一个ID改为一个类,但没有运气。
这是jQuery的方法:
$('.btnRemove').click(function() {
var productId = $(".ProductId").val();
$.ajax({
type: "POST",
url: "functions/deleteCartItem.php",
data: "productId="+productId+ "",
success: function(msg){
alert(msg);
}
})
})
一个可能的解决方案,我能想到的是一个独特的id
添加到每个按钮,以便它们可以被识别,不仅名字,但也id
。然而,这在从jQuery方法中读取时会产生问题。
任何想法?
欢呼队友它的工作原理...良好的思维BTW) – 2011-12-22 09:57:19