Skip to content

Instantly share code, notes, and snippets.

@springcome
Created October 18, 2013 01:56
Show Gist options
  • Save springcome/7035321 to your computer and use it in GitHub Desktop.
Save springcome/7035321 to your computer and use it in GitHub Desktop.
checkbox, jquery
<input type="checkbox" name="chk" id="chk1" value="1" />1번
<input type="checkbox" name="chk" id="chk2" value="2" />2번
<input type="checkbox" name="chk" id="chk3" value="3" />3번
// checkbox checked여부확인
console.log($('#chk1').is(':checked'));
$(':input[name=chk]').each(function(){
if($(this).is(':checked')){
console.log('true');
}else{
console.log('false');
}
});
// value를 가지고 checked하고자 할때
$(':input:checkbox[name=chk][value=2]').attr('checked', true);
// checked되어 있는 모든 checkbox를 알고자 할때
$(':input:checkbox[name=chk]:checked').each(function(){
console.log($(this).val() + " : " + this.id);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment