繁体   English   中英

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

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

我的复选框

  <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 库

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

JS代码

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

但它不起作用。我希望未选中索引 2。但它不起作用。

请查看图片请查阅

而不是在 jQuery 元素集合上引用数组索引(无论如何都不起作用) - 坚持使用 JQ 并使用.eq()

此外,您的代码将一个不可见的复选框( opacity: 0 )设置为 false ( prop("checked", false); ) - 当它们都未选中时...

在此,我已将其设置为可见“选中”复选框。 那只是一个 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM