1
上午有表數據(檢索從MySQL表中的數據,並獲取到表)。表包含幾個記錄。我想顯示覆選框的值與輸入框值和複選框,當我點擊按鈕在PHP中。選中的複選框值和選中的輸入已使用連接功能正確顯示。但用複選框檢查顯示不正確。在我的代碼中,當我點擊按鈕時,顯示所有選中的檢查值。我的問題顯示只checkbox複選框使用連接函數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);
});
這裏,
我得到選中的複選框,並檢查輸入值。我的問題顯示檢查值檢查複選框。
感謝@
其工作得到了輸出 – user3839366
類可以通過大量的HTML元素的共享,即許多HTML元素可以具有相同的類,但ID是別的,ID不能是紅色元素,但每個元素ID將是唯一的。 –