简体   繁体   中英

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

我正在为一个客户端制作一个表单,他给我的任务是在未选中的某个复选框时创建一个显示/隐藏效果。

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 .

$("#checkboxID").change(function() { $("#targetToHideAndShow").toggle() } );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM