0

我想针对一个特定的复选框,例如下面的“is-wine”,但不确定语法,理想情况下是否可以在一行中完成。

关于如何做到这一点的任何想法?基本上只想选择'is-wine'复选框而不是其他复选框。

谢谢

$(document).ready(function(){
  $('.click-me').on('click',function(){
 // doesn't work
 //$('.chex input .is-wine').attr('checked',status);  
   $('.chex input').each( function() {
      $(this).attr('checked',status);
    });
  });
});
</script>
</head>
<body>
here i am withing sub
<div id='my-killer-id'>
  <div class='click-me'>clicke me for is-wine</div>
  <div class='chex'>
  <input type='checkbox' class='is-wine' /><br />
  <input type='checkbox' class='is-coffee' /><br />
  <input type='checkbox' class='is-tea' /><br />
  <input type='checkbox' class='is-cocktail' /><br />
</div>
</div>
4

1 回答 1

1

这应该没有空间..

$('.chex input.is-wine').attr('checked',status);  

如果您在那里放置一个空格,它将转到输入的孩子(没有孩子)

if($('.chex input.is-wine').is(':checked')){
        alert('is wine is Checked !!')
     }      
     else{
       alert('is wine is not Checked !!')
    }  

检查这个小提琴

你可以为此想出多个选择器..因为这个类是独一无二的

$('.chex .is-wine').attr('checked',status); 

OR 

$('.is-wine').attr('checked',status); 

OR

$('.chex input[type=checkbox][class=is-wine]').attr('checked',status); 
于 2012-09-10T22:35:14.800 回答