Php 如果选中该行第一列中的一个或多个复选框,如何将值传递给jquery?
是,Php 如果选中该行第一列中的一个或多个复选框,如何将值传递给jquery?,php,jquery,codeigniter,Php,Jquery,Codeigniter,是, 如果选中了标题复选框,我需要在表的第一列中启用所有复选框 我需要将一个或多个或所有选中复选框的行id传递给jQuery函数 针对您的问题的非常糟糕的jQuery解决方案: 在迭代表中的每个tr时,执行如下操作: // assume you have an array like: $array = array( '0' => array( 'name' => 'bob', 'pet' => 'dog' ),
针对您的问题的非常糟糕的jQuery解决方案: 在迭代表中的每个tr时,执行如下操作:
// assume you have an array like:
$array = array(
'0' => array(
'name' => 'bob',
'pet' => 'dog'
),
'1' => array(
'name' => 'josh',
'pet' => 'cat'
),
);
for($i=0;$i<count($array);$i++) { ?>
<td><input type="checkbox" name="rows[<?=$i?>]" /><td><?=$array[$i]['name']?></td><td><?=$array[$i]['pet'];?></td>
<? } ?>
//假设您有如下数组:
$array=array(
“0”=>数组(
“name”=>“bob”,
“宠物”=>“狗”
),
“1”=>数组(
“name”=>“josh”,
“宠物”=>“猫”
),
);
对于($i=0;$i)
发布后,您将在帖子中获得一个包含行索引的数组,您可以进一步遍历该数组
如果您需要更多的示例代码,我很乐意为您提供一些。这将有助于您入门。:)将此类型结构用于html
<fieldset>
<!-- these will be affected by check all -->
<div><input type="checkbox" class="checkall"> Check all</div>
<div><input type="checkbox"> Checkbox</div>
<div><input type="checkbox"> Checkbox</div>
<div><input type="checkbox"> Checkbox</div>
</fieldset>
<fieldset>
<!-- these won't be affected by check all; different field set -->
<div><input type="checkbox"> Checkbox</div>
<div><input type="checkbox"> Checkbox</div>
<div><input type="checkbox"> Checkbox</div>
</fieldset>
谢谢你的回复。但我已经设计了一个来自ajax函数的html表,在第一列中包含复选框,如果我在第一列中单击单个复选框或多个或全部复选框,如果我单击一个按钮,它需要将id(指数据库中的值)传递给jquery函数。从这个函数中,我需要将它插入或更新到数据库中。
$(function () {
$('.checkall').click(function () {
$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
var x = $(this).parents('fieldset:eq(0)').find(':checkbox').attr('id');
});
});