gpt4 book ai didi

javascript - 检查所有复选框,如果它们具有相同的值

转载 作者:太空宇宙 更新时间:2023-11-04 15:02:59 24 4
gpt4 key购买 nike

这是我的html代码:

 <ul>
<li>
<input name="Services[]" class="form-control" value="Canbeprivatized" id="Canbeprivatized" type="checkbox"><label for="Canbeprivatized">Can be privatized </label>
</li>
<li>
<input name="Services[]" class="form-control" value="Englishspoken" id="Englishspoken" type="checkbox"><label for="Englishspoken">English spoken </label>
</li>
<li>
<input name="Services[]" class="form-control" value="Françaisparle" id="Françaisparle" type="checkbox"><label for="Françaisparle">Français parlé </label>
</li>
<li>
<input name="Services[]" class="form-control" value="Petsallowed" id="Petsallowed" type="checkbox"><label for="Petsallowed">Pets allowed </label>
</li>
<li>
<input name="Services[]" class="form-control" value="Piscine" id="Piscine" type="checkbox"><label for="Piscine">Piscine </label>
</li></ul>

jQuery 代码:

var tab = new Array();
tab = data.services.split(",");// data is values of Checkboxes inserted in create form, so now i need to show it because this is edit form

我的问题是如何选中所有值等于选项卡中值的复选框。需要你的帮助,谢谢

最佳答案

如下操作,在tab上迭代:

for (i = 0; i < tab.length; i++)
$('input[type=checkbox][value=' + tab[i] + ']').prop("checked", true);

关于javascript - 检查所有复选框,如果它们具有相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31700030/

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