在预订页面的视图/编辑部分,我有一个通过AJAX生成的表格,其中包含预订时间,房间号,日期和编辑预订,其中包含一个分配给它的值的按钮,从0开始,根据生成的行数上升,因此单击时,我可以通过值编号来定位该行,以获取要发送到我的SQL语句的正确字段。
<? php
function usersBookings($group) {
$q = $this->connection->prepare("SELECT `timeslot`.`shortDesc`, `booking`.`room_ID`, `booking`.`date` FROM `booking` JOIN `timeslot` ON `timeslot`.`blockID` = `booking`.`block_ID`
WHERE `team_name` LIKE ? ORDER BY `booking`.`date` ASC");
$q->execute(Array($group));
$str = "<table id='userTable' style='width:80%'>
<tr>
<th style='border-bottom:1px solid black'>Booking Time</th>
<th style='border-bottom:1px solid black'>Room Number</th>
<th style='border-bottom:1px solid black'>Date</th>
<th style='border-bottom:1px solid black'>Edit Booking</th>
</tr>";
$counter = 0;
while ($result = $q->fetch()) {
$str .= "<tr>
<td>$result[0]</td>
<td>$result[1]</td>
<td>$result[2]</td>
<td><button class='edit_btn' value='$counter'>Edit</button></td>
</tr>";
$counter++;
}
$str .= "</table>";
return $str;
}
?>
现在我正在尝试定位通过jQuery单击哪个按钮以定位该特定行:
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$buttonNo = $('#userTable button').val(); // Not sure how to target.
$field1 = $('#userTable tr:nth-child(' + $buttonNo + ') td:nth-child(1)');
$field2 = $('#userTable tr:nth-child(' + $buttonNo + ') td:nth-child(2)');
$field3 = $('#userTable tr:nth-child(' + $buttonNo + ') td:nth-child(3)');
</script>
我不知道如何定位正确的点击按钮。
请原谅代码,对PHP和jQuery来说是全新的。
答案 0 :(得分:3)
您可以使用git status
事件并获取.click
:
this
答案 1 :(得分:0)
$(document).delegate('#userTable button', 'click', function() {
$buttonNo = $(this).val();
});