How To Show And Hide Input Fields Based On Radio Button Selection

前端 未结 8 1225

Here is the code to show input fields depending on radio selection like:

SCRIPT



        
8条回答
  •  情书的邮戳
    2020-11-29 01:55

    You'll need to also set the height of the element to 0 when it's hidden. I ran into this problem while using jQuery, my solution was to set the height and opacity to 0 when it's hidden, then change height to auto and opacity to 1 when it's un-hidden.

    I'd recommend looking at jQuery. It's pretty easy to pick up and will allow you to do things like this a lot more easily.

    $('#yesCheck').click(function() {
        $('#ifYes').slideDown();
    });
    $('#noCheck').click(function() {
        $('#ifYes').slideUp();
    });
    

    It's slightly better for performance to change the CSS with jQuery and use CSS3 animations to do the dropdown, but that's also more complex. The example above should work, but I haven't tested it.

提交回复
热议问题