简体   繁体   English

如何在js中的复选框数组上将选中的属性设置为false

[英]How to set checked properties false on checkbox array in js

My chechkbox我的复选框

  <div class="col-md-3" style="padding-left:15 !important;">
                            <div class="icheckbox_minimal-grey checked disabled" style="position: relative;"><input class="alanlar" type="checkbox" disabled="" name="gunlukAlanlar[]" value="tarih" checked="" style="position: absolute; opacity: 0;"><ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins></div>
                            <label class="control-label" style="margin-left: 5px;color:red;">Tarih</label>
                            </div>
<div class="col-md-3" style="padding-left:15 !important;">
                        <div class="icheckbox_minimal-grey checked disabled" style="position: relative;"><input class="alanlar" type="checkbox" disabled="" name="gunlukAlanlar[]" value="saat" checked="" style="position: absolute; opacity: 0;"><ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins></div>
                        <label class="control-label" style="margin-left: 5px;color:red;">Saat</label>
                        </div>
<div class="col-md-3" style="padding-left:15 !important;">
                        <div class="icheckbox_minimal-grey checked disabled" style="position: relative;"><input class="alanlar" type="checkbox" disabled="" name="gunlukAlanlar[]" value="Order Adı" checked="" style="position: absolute; opacity: 0;"><ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins></div>
                        <label class="control-label" style="margin-left: 5px;color:red;">Order Adı</label>
                        </div>

JQuery Lib JQuery 库

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> 

Js Code JS代码

$("input[name='gunlukAlanlar[]']")[2].prop("checked", false);

But its not working.I'm want unchecked have index 2.But its not working.但它不起作用。我希望未选中索引 2。但它不起作用。

Please review image请查看图片请查阅

Instead of referencing an array index on a jQuery element collection (which doesn't work anyways) - stick with JQ and use .eq()而不是在 jQuery 元素集合上引用数组索引(无论如何都不起作用) - 坚持使用 JQ 并使用.eq()

Also your code was setting an invisible checkbox ( opacity: 0 ) to false ( prop("checked", false); ) - when they were all unchecked to begin with so...此外,您的代码将一个不可见的复选框( opacity: 0 )设置为 false ( prop("checked", false); ) - 当它们都未选中时...

In this, I've set it so 'checked' checkboxes are visible.在此,我已将其设置为可见“选中”复选框。 That is just a css class so it's easy to get rid of.那只是一个 css class 所以很容易摆脱。

 $("input[name='gunlukAlanlar[]']").eq(1).prop("checked", false);
 <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <label><input class="alanlar" type="checkbox" name="gunlukAlanlar[]" id="gunlukAlanlar[]" checked value="saat" /> //index 0</label> <label><input class="alanlar" checked type="checkbox" name="gunlukAlanlar[]" id="gunlukAlanlar[]" value="modelii">//index 1</label> <label><input class="alanlar" checked type="checkbox" name="gunlukAlanlar[]" id="gunlukAlanlar[]" value="tarih">//index 2</label> <label><input class="alanlar" checked type="checkbox" name="gunlukAlanlar[]" id="gunlukAlanlar[]" value="musteri">//index 3</label>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复选框设置为选中 = false 不起作用 - checkbox set to checked = false not working 如果它的值在数组中,如何设置选中的复选框 - How set checked checkbox if it's value is in array 如何设置基于一个数组中的值选中的复选框并将值添加到另一个数组(如果选中),否则使用angular js删除? - how to set checkbox checked based on value in one array and add value to another array if checked otherwise remove using angular js? 设置为false时,为什么要选中一个新创建的复选框? - Why is a newly created checkbox checked when I set checked to false? 如何将复选框设置为有条件地选中 - How to set a checkbox as checked conditionaly 如何在选中的表格中设置复选框? - How to set checkbox in a table checked? 如何访问材质 UI 的选中属性<Checkbox/>并在按下另一个图标(删除图标)时将其设置为 false? - How to access checked property of a material UI <Checkbox/> and set it equal to false when pressing another icon (delete icon)? 我们如何在html中分别为复选框处于选中或未选中状态的复选框的响应设置“ True”或“ False”字符串? - How do we set “True” or “False” strings to the response of a checkbox for its checked or unchecked state respectively in html? 如何在 HTML 表中用选中的复选框替换“TRUE”和用未选中的复选框替换“FALSE”? - How to replace "TRUE" with a checked checkbox and "FALSE" with a nonchecked checkbox in an HTML table? ng-model设置为false时,脏复选框仍处于选中状态 - Dirty checkbox still checked when ng-model set to false
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM