gpt4 book ai didi

jquery - 使用 .each() 循环检查复选框和 .append 数据

转载 作者:行者123 更新时间:2023-12-01 02:01:00 24 4
gpt4 key购买 nike

我在表中有一系列行,每行都有不同的值(价格),并且每行都有一个复选框。该表是通过 PHP 循环生成的。

echo "<table border='0' cellpadding='10' id='booking-list'><tr>";
echo "<th>Booking ID</th><th>Customer ID</th><th>Start Date</th><th>Course Name</th><th>Amount Due</th><th>Date Payment Due</th><th>Add to basket</th></tr>";
$x = 0;
while ($row = mysql_fetch_assoc($query)) {
$balance = $row['price'] - $row['deposit'];

echo "<td>" .$row['booking_id']. "</td><td>" .$cust_id. "</td><td>" .$row['start_date']. "</td><td>" .$row['name']. "</td><td>" .$balance. "</td><td>" .$row['balance_due_date']. "</td><td><input type='checkbox' name='' value='" .$x. "' /></td></tr>";
$x++;
}
echo "</tr><table>";

对于选中的每个复选框,我想将特定值 ($balance) 添加 (.append) 到表单 输入字段。附加部分似乎有效,但我不确定如何循环遍历 jQuery 中的每个选中的复选框以获取我需要的值。

function(){
$('#booking-list input:checkbox').change(
function(){
if ($(this).is(':checked')) {
$('<input />').attr({
type: 'text',
id: 'foo',
name: 'bar',
value: '<?php echo $balance; ?>'
}).appendTo('#paypal-form form').text($(this).val());
} else {
$('#paypal-form input:contains('+$(this).val()+')').remove();
}
});

现在,我只能获取最后生成的 $balance 值。

谢谢。

最佳答案

要选择所有选中的复选框,您可以执行以下操作:

  $('#booking-list input:checkbox:checked').each(function(){
$(this).doSomething();//this is the checked checkbox
});

关于jquery - 使用 .each() 循环检查复选框和 .append 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12124938/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com