I have 2 radio buttons, what I want is if a user selects the top radio button then hide a textbox.
Not sure how to开发者_StackOverflow中文版 bind an event to a radio button.
Something like this:
<input type="radio" name="foo" value="top" />
<input type="radio" name="foo" value="bottom" />
And in jQuery:
$('input[name=foo]').click(function() {
if($(this).val() == "top") {
$('#textbox').hide();
} else {
$('#textbox').show();
}
});
click
because change
doesn't seem to work correctly on IE.
This will allow you to add the event to a selected radio, in case your radio's do not have the same name.
$('checkbox-selector').click(function() {
if ($(this).is(':checked')) {
$('textbox-selector').hide();
}
else {
$('textbox-selector').show();
}
});
精彩评论