admin管理员组文章数量:1332638
<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
var optrep0= jQuery(':checkbox:checked').map(function () {
return this.value;
}).get();
And send optrep0
variable to server, but it will send every checked value. So, I want to send only specified div
s only per variable, I also tried
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
<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
var optrep0= jQuery(':checkbox:checked').map(function () {
return this.value;
}).get();
And send optrep0
variable to server, but it will send every checked value. So, I want to send only specified div
s only per variable, I also tried
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
Share edited Jun 2, 2015 at 11:16 Arslan Ali 17.8k9 gold badges63 silver badges83 bronze badges asked Jun 2, 2015 at 7:50 Reids Meke MekeReids Meke Meke 3574 silver badges14 bronze badges 7-
3
Why you have same
id
? – Radonirina Maminiaina Commented Jun 2, 2015 at 7:52 - Yes. because server fixed send same id for the selector, I cannot change the name thought, but I can only create parent id to make the option unique – Reids Meke Meke Commented Jun 2, 2015 at 8:00
-
So generate a different id, for example:
warna1
,warna2
, or usetimestamp
. :) – Radonirina Maminiaina Commented Jun 2, 2015 at 8:02 - As I said before, sub id name "warna" cannot change, it should be used as is as due server issue, just need to find how to solve this case – Reids Meke Meke Commented Jun 2, 2015 at 8:04
- Yeah, name cannot be changed, but if input is generated into a loop, it's easy to do it, or use javascript to do this! ;) – Radonirina Maminiaina Commented Jun 2, 2015 at 8:07
3 Answers
Reset to default 6Give space in >
and use dot
for class warna
Live Demo
var optrep0= jQuery('#optrep0 > .warna:checkbox:checked').map(function () {
return this.value;
}).get();
Try using descendant selector by putting a >
and don't use :checkbox
, only :checked
is needed
var optrep0= jQuery('#optrep0 > :checked').map(function () {
return this.value;
}).get();
I would say the preferable way is
var optrep0= jQuery('#optrep0 > .warna:checkbox:checked').map(function () {
return this.value;
}).get();
DEMO
本文标签: javascriptHow to get checked checkbox value of specified div in jQueryStack Overflow
版权声明:本文标题:javascript - How to get checked checkbox value of specified div in jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742263608a2442973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论