How to hide/show content when checkbox is checked/unchecked?

后端 未结 2 1359
死守一世寂寞
死守一世寂寞 2021-01-19 23:28

I\'m working on a form for a client and he has given me the task to create a show/hide effect when certain checkbox in unselected.

相关标签:
2条回答
  • 2021-01-20 00:27

    This function should do it:

    $("#yourCheckboxID").click(function ()
    {
        if ($("#yourCheckboxID").attr("checked"))
        {
            $("#yourDivID").show();
        }
        else
        {
            $("#yourDivID").hide();
        }              
    });
    

    It will hide or show a specific div based on a checkbox. I wasn't sure exactly what you were trying to hide or show so I just assumed a div.

    0 讨论(0)
  • 2021-01-20 00:27
    $("#checkboxID").change(function() { $("#targetToHideAndShow").toggle() } );
    
    0 讨论(0)
提交回复
热议问题