[英]How to get checked checkbox value of specified div in jQuery
<td id="optrep0">
<input type="checkbox" value="1" class="warna" id="warna" name="warna[]">
<input type="checkbox" value="2" class="warna" id="warna" name="warna[]">
</td>
<td id="optrep1">
<input type="checkbox" value="1" class="warna" id="warna" name="warna[]">
<input type="checkbox" value="2" class="warna" id="warna" name="warna[]">
</td>
<td id="optrep2">
<input type="checkbox" value="1" class="warna" id="warna" name="warna[]">
<input type="checkbox" value="2" class="warna" id="warna" name="warna[]">
</td>
I need to find checked value of specified div
s having id
s: optrep0
, optrep1
, optrep2
above, I have tried using 我需要找到id
s的指定div
的检查值: optrep0
, optrep1
, optrep2
以上,我试过用
var optrep0= jQuery(':checkbox:checked').map(function () {
return this.value;
}).get();
And send optrep0
variable to server, but it will send every checked value. 并将optrep0
变量发送到服务器,但它将发送每个选中的值。 So, I want to send only specified div
s only per variable, I also tried 所以,我想只发送每个变量的指定div
,我也尝试过
var optrep0= jQuery('#optrep0>#warna:checkbox:checked').map(function () {
return this.value;
}).get();
PS: sub id name on td id cannot be changed as is as, I only need javascript example how to solve this case, thank you :D PS:td id上的sub id名称不能改为,我只需要javascript示例如何解决这种情况,谢谢:D
Try using descendant selector by putting a >
and don't use :checkbox
, only :checked
is needed 尝试使用后代选择器,只需输入一个>
,不要使用:checkbox
:仅需要:checked
var optrep0= jQuery('#optrep0 > :checked').map(function () {
return this.value;
}).get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.