开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜