开发者

Using jQuery, hide a textbox if a radio button is selected

开发者 https://www.devze.com 2022-12-24 05:07 出处:网络
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:

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();
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号