如何取消選中一組復選框的前兩個復選框?

[英]How to uncheck first two checkbox of a group of check box?


I have a list of checkboxes. Checkbox name is CHKBOXPAYANYONE. It has four checkboxes. I want to unchecked first two check box. I am getting the checkbox item by using $("input[name=CHKBOXPAYANYONE]")[0] and $("input[name=CHKBOXPAYANYONE]")[1] . So please suggest how to uncheck them.

我有一個復選框列表。復選框名稱為CHKBOXPAYANYONE。它有四個復選框。我想取消選中前兩個復選框。我通過使用$(“input [name = CHKBOXPAYANYONE]”)[0]和$(“input [name = CHKBOXPAYANYONE]”)[1]獲取復選框項。所以請建議如何取消選中它們。

3 个解决方案

#1


2  

Use the :lt() to select the first 2 elements.

使用:lt()選擇前2個元素。

.prop("checked",false) will uncheck the checkbox.

.prop(“checked”,false)將取消選中該復選框。

$("input[name=CHKBOXPAYANYONE]:lt(2)").prop("checked",false)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="CHKBOXPAYANYONE" type="checkbox" checked/>
<input name="CHKBOXPAYANYONE" type="checkbox" checked/>
<input name="CHKBOXPAYANYONE" type="checkbox" checked/>
<input name="CHKBOXPAYANYONE" type="checkbox" checked/>

#2


1  

Try this:

嘗試這個:

$("input[name=CHKBOXPAYANYONE]").eq(0).prop("checked",false);
$("input[name=CHKBOXPAYANYONE]").eq(1).prop("checked",false);

OR

要么

$("input[name=CHKBOXPAYANYONE]:eq(0)").prop("checked",false);
$("input[name=CHKBOXPAYANYONE]:eq(1)").prop("checked",false);

Or You can use the loop also. For more read the :eq selector.

或者您也可以使用循環。有關更多信息,請閱讀:eq選擇器。

And How to uncheck the checkbox.

以及如何取消選中該復選框。

#3


1  

Supporting @Carsten Løvbo Andersen answer, you can also use .checked html property:

支持@CarstenLøvboAndersen回答,你也可以使用.checked html屬性:

$("input[name=CHKBOXPAYANYONE]")[0].checked = false;
$("input[name=CHKBOXPAYANYONE]")[1].checked = false;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="CHKBOXPAYANYONE" type="checkbox" checked/>
<input name="CHKBOXPAYANYONE" type="checkbox" checked/>
<input name="CHKBOXPAYANYONE" type="checkbox" checked/>
<input name="CHKBOXPAYANYONE" type="checkbox" checked/>


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/06/07/72518740ee7b1800b46285aa019eb71e.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com