gpt4 book ai didi

jquery - 仅选中列表中的复选框

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

我有一个用户名循环:

<div id=woohoo class=hey_im_here>
<input class="search" placeholder="Enter a name">
<br><br>
<?php
$numbers = '12345';
$unityResult = getUnityEmail();
$houseResult = getHouses();
$count = mysqli_num_rows($houseResult);
for ($x=0;$x<$count;$x++){
echo "<div id='memberList$x' class='membr' style='display:inline-block;vertical-align:top'>";
echo "<fieldset class=fieldname style='display:inline'>";
if( $numbers[$x] == 1){ echo "<legend class=name_legend>u (red)</legend>"; }
else if( $numbers[$x] == 2){ echo "<legend class=name_legend>n (purple)</legend>"; }
else if( $numbers[$x] == 3){ echo "<legend class=name_legend>i (blue)</legend>"; }
else if( $numbers[$x] == 4){ echo "<legend class=name_legend>t (green)</legend>"; }
else{ echo "<legend class=name_legend>y (yellow)</legend>"; }
echo "<ul class='list'>";
echo "<li><input class='allHouses' id='allHouses' data-username='all' type='checkbox' name=uid[] value='all'> "
. "<label for='allHouses'>All</label></li>";
while ($row_unity = mysqli_fetch_array($unityResult)) {

if ($row_unity['fkhouseid'] == $numbers[$x]) {

format_member_list_filters( $row_unity);
}
}
echo "</ul>";
echo "</fieldset>";
echo "<br>";
echo "</div>";
mysqli_data_seek($unityResult, 0);
} ?>
</div>

我收到后:

enter image description here

然后我想允许用户通过单击“全部”来选择每个字母下的所有用户名。我如何使用 jquery 允许用户检查当前列表的所有复选框。这是我尝试过的:

$(".allHouses").click(function(){
var checkboxes = $(this).closest('li').find(':checkbox').not($(this));
checkboxes.prop('checked', $(this).is(':checked'));
});

最佳答案

您需要找到最接近的ul而不是li

$(".allHouses").click(function(){
var checkboxes = $(this).closest('ul').find(':checkbox').not($(this));
checkboxes.prop('checked', $(this).is(':checked'));
});

closest('li') 将返回 .allHouses 的直接父级,因此它无法找到其他复选框。

关于jquery - 仅选中列表中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48455317/

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