我想选择我单击的所有子复选框。例如,在下面的代码段中,我希望它选择第一个“is-wine”而不是第二个。目前,它也没有选择。
关于如何使它工作的任何想法?
谢谢
<script>
$(document).ready(function() {
$('.click-me').on('click',function(){
console.log('about to set');
console.log('here is val: ' + $('.chex input.is-wine').attr('checked'));
if ( $('.chex input.is-wine').children().is(':checked') ) {
$('.chex input.is-wine').children().attr('checked',false);
} else {
$('.chex input.is-wine').children().attr('checked',status);
}
console.log('after setting');
});
});
</script>
<body>
here i am withing sub
<div id='my-killer-id'>
<div class='click-me'>click me to start</div>
<div class='chex'>
<input type='checkbox' class='is-wine' /><br />
<input type='checkbox' class='is-coffee' /><br />
</div>
</div>
<div id='other-vals'>
<div class='chex'>
<input type='checkbox' class='is-wine' /><br />
<input type='checkbox' class='is-coffee' /><br />
</div>
</div>
</body>
编辑#1
所以这是我要选择的更现实的标记
<div id='my-killer-id'>
<div class='click-me'>clicke me to start</div>
<div class='chex'>
<!-- would select this -->
<input type='checkbox' class='is-wine' /><br />
<input type='checkbox' class='is-coffee' /><br />
<div class='other-things'>
<!-- would select this -->
<input type='checkbox' class='is-wine' />
<input type='checkbox' class='is-coffee' />
<div class='even-more-things'>
<!-- would select this -->
<input type='checkbox' class='is-wine' />
<input type='checkbox' class='is-coffee' />
</div>
</div>
</div>
</div>
<div id='other-vals'>
<div class='chex'>
<!-- would not select this -->
<input type='checkbox' class='is-wine' /><br />
<input type='checkbox' class='is-coffee' /><br />
</div>
</div>