0

I have a form with checkboxes - if one of these is checked, there is some jquery that applies the css class checkboxed.

I have another div further down the page that is hidden by default - but if any of the form checkboxes are checked, it should become visible.

I'd like to use something like this

<div class="<%= "hide" unless checkboxed.exists? %>">

but obviously that doesn't work. Is there a way to test if a css class exists on a given page? I know I'll have to use jQuery, but how to then tie this in with the conditional CSS class in the hidden div?

4

2 回答 2

1

您需要将显示逻辑的 div 添加到您对复选框做出反应的位置。添加可能如下所示:

if($('.checkboxed').length)
    $('#hiddenDiv').show();

您的隐藏 div 必须有一个 ID,这里我假设id="hiddenDiv".

于 2013-10-17T12:11:49.260 回答
0
var checkbox = $('checkbox').attr("checked");

if (checkbox == 'checked') {
    $('#divID').show(); // #divID is the ID for the hidden DIV which you want to show.
}
于 2013-10-17T12:12:04.397 回答