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

后端 未结 2 1358
死守一世寂寞
死守一世寂寞 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.

提交回复
热议问题