【发布时间】:2011-12-21 21:17:10
【问题描述】:
我有一个输入按钮:
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 id="itemName" class="itemElements">'. $row["Name"] .'</span></td>';
echo '<td width="135"><span id="qtyNum">('. $row["Qty"] .')</span> <br />';
echo '<span id="qtyRemoveLink"><input class="linkbtn" type="submit" id="btnRemove" value="Remove"></td>';
echo '<td width="180"><span id="orderStatus" class="itemElements">In Stock Usually dispatched within 24 hours</span></td>';
echo '<td width="175" id="itemPriceRow"><span id="itemPrice">€ '. $row["Price"] .'</span></td>';
echo '</tr>';
echo '</tbody>';
echo '</table>';
echo '<br>';
}
我正在尝试使用此方法在单击按钮时触发事件,但是该事件仅针对第一行中生成的第一个按钮触发。我正在使用这种方法:
$(document).ready(function() {
$('#btnRemove').click(function() {
alert("test");
});
});
有什么办法可以解决这个问题吗?我知道在 C# 中有行数据绑定方法,但是在 jQuery 中,如果它存在,我现在不知道。谢谢
【问题讨论】:
-
正如下面的评论中提到的——你在整个地方都错误地使用了 id。这会导致您的特定情况出现问题,但您还需要更新所有标记以正确使用 ID(或实际上不使用 ID)。
标签: php jquery button triggers rows