Javascript: Radio button not checked value
I have variable that get's value of checked radio button named: parentcheck I wanna check if parentcheck is checked and =0 or if not checked. Tried if(parentcheck=='') for "not checked". it doesn't work.
var parentcheck = $(".parentcheck:checked").val();
if(parentcheck=='0'){
$("#parent").hide();
}
if(parentch开发者_如何学Pythoneck==''){
$("#parent").hide();
}
if(!$('.parentcheck:').is(':checked')) {
$('#parent').hide();
}
First off, that selector you use will only return you elements with the class .parentcheck
which are actually checked. By definition, that means every element it returns (as it always returns a set in jQuery) will be checked, so if the element you're looking for isn't checked then it won't be in the set. Something like this might be what you're after:
if (! $(".parentcheck").is(":checked")) {
$("#parent").hide();
}
I actually can't get your question, it should help you.
var $check = $('.parentCheck'); if ($check.val() == '' || toString($check.val()) == "0") { // do your stuff } if ($check.attr('checked')) { // checked, do your stuff } else { // is not checked, do another stuff }
Use .attr('checked')=='checked'
精彩评论