【发布时间】:2017-07-03 06:18:31
【问题描述】:
我有表数据(从 mysql 表中检索数据并提取到表中)。表包含几条记录。当我单击 php 中的按钮时,我想显示带有输入框值和复选框的选中复选框值。选中的复选框值和选中的输入已使用连接功能正确显示。但检查复选框未正确显示。在我的代码中,当我单击按钮时,会显示所有选中的检查值。我的问题是使用连接功能仅显示带有 checkbax 的选中复选框。
我的桌子:
<table border="0" cellpadding="10" cellspacing="1" width="500" class="tblListForm">
<tr class="listheader">
<td></td>
<td>Username</td>
<td>First Name</td>
<td>Last Name</td>
<td>Permissions</td>
<td>CRUD Actions</td>
</tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
if($i%2==0)
$classname="evenRow";
else
$classname="oddRow";
?>
<tr class="<?php if(isset($classname)) echo $classname;?>">
<td><input type="checkbox" class="chk_id" name="chk_id" id="chk_id" value="<?php echo $row["userId"]; ?>" /></td>
<td><?php echo $row["userName"]; ?></td>
<td><input type="text" name="firstName" class="firstName" id="firstName" value="<?php echo $row["firstName"];?>" /></td>
<td><?php echo $row["lastName"]; ?></td>
<td><input type="checkbox" name="grant" class="grant" id="grant" value="Y" /></td>
<td><a href="edit_user.php?userId=<?php echo $row["userId"]; ?>" class="link"><img alt='Edit' title='Edit' src='images/edit.png' width='15px' height='15px' hspace='10' /></a> <a href="delete_user.php?userId=<?php echo $row["userId"]; ?>" class="link"><img alt='Delete' title='Delete' src='images/delete.png' width='15px' height='15px'hspace='10' /></a></td>
</tr>
<?php
$i++;
}
?>
</table>
<input type="button" id="save_value" name="save_value" value="Save" />
我尝试过的 jquery 代码:
$('#save_value').click(function () {
alert("Checkbox running");
var chk_id = [];
var firstName = [];
var grant = [];
$.each($("input[ id='chk_id']:checked"), function () {
chk_id.push($(this).val());
firstName.push($(this).parent().parent().find("#firstName").val());
grant.push($(this).parent().parent().find($("#grant").is(':checked'));
});
alert(chk_id);
alert(firstName);
alert(grant);
});
这里,
正在检查复选框并检查输入值。我的问题是用检查值显示选中的复选框。
谢谢@
【问题讨论】:
-
它的工作得到了输出
-
类可以由许多 HTML 元素共享,即许多 HTML 元素可以具有相同的类,但 ID 是其他东西 ID 不能由元素共享,但每个元素的 ID 将是唯一的.