【发布时间】:2015-07-16 17:25:46
【问题描述】:
当在 UL > LI 中找到活动的类时,我如何隐藏文本框
当我应该显示它的标签和文本框时,它应该被隐藏。我正在尝试获取选定复选框的值并将其隐藏但无法到达那里。
$('ul.multiselect-container').has('li.active').css('display', 'none');
<ul class="multiselect-container dropdown-menu">
<li class="active"><a tabindex="0"><label class="checkbox"><input type="checkbox" value="1"> Paypal</label></a>
</li>
<li class="active"><a tabindex="0"><label class="checkbox"><input type="checkbox" value="2"> Stripe</label></a>
</li>
<li class=""><a tabindex="0"><label class="checkbox"><input type="checkbox" value="3">Beanstream</label></a>
</li>
</ul>
<label for="Configuration_paypalId" class="control-label">Paypal Id</label>
<input type="text" value="" id="Configuration_paypalId" name="Configuration[paypalId]" maxlength="60" class="span4">
<br>
<label for="Configuration_stripeId" class="control-label">Stripe Id</label>
<input type="text" value="" id="Configuration_stripeId" name="Configuration[stripeId]" maxlength="60" class="span4">
<br>
<label for="Configuration_beanId" class="control-label">Bean Id</label>
<input type="text" value="" id="Configuration_beanId" name="Configuration[beanId]" maxlength="60" class="span4">
更新
抱歉,如果问题不清楚, 当我单击第一个复选框时,说贝宝,然后只有贝宝标签和文本框应该出现在下面,其余的文本框 2 及其标签应该隐藏。我猜我们需要用 each() 循环遍历 UL 标记。
这是一个小提琴。 http://jsfiddle.net/nzw7LoL0/5/
更新 2
我无法向名为 option 和 option 1 的 div 添加一个类,因为 html 是使用框架生成的。所以我需要隐藏具有.control-grouphttp://jsfiddle.net/d280wqr4/5/类的行
$('input:checkbox').on('change', function () { // Apply change listener to checkboxes
if ($(this).is(':checked')) { // If this checkbox is checked, show the relevant element
$('.option' + $(this).prop('value'))find('.control-group').show();
} else { // Otherwise, hide the relevant element
$('.option' + $(this).prop('value')).find('.control-group')hide();
}
});
<div class="control-group "><label for="Configuration_paypalId" class="control-label">Paypal Id</label><div class="controls"><input type="text" value="" id="Configuration_paypalId" name="Configuration[paypalId]" maxlength="60" class="span4 option option1"><p class="help-block">Merchant id or email of the Paypal account</p></div></div>
<div class="control-group "><label for="Configuration_stripeId" class="control-label">Stripe Id</label><div class="controls"><input type="text" id="Configuration_stripeId" name="Configuration[stripeId]" maxlength="60" class="span4 option option2"><p class="help-block">Stripe id or email of the Stripe account</p></div></div>
【问题讨论】:
-
所有这些输入字段?
-
@ArunPJohny 当我点击第一个复选框时,说贝宝,然后应该只出现贝宝标签和文本框,其余的文本框 2 及其标签应该隐藏。我猜我们需要用 each() 循环遍历 UL 标签
-
你的问题需要我澄清一下,我们很难理解你真正想要什么?
-
@JoshStevens 请看这个小提琴。 jsfiddle.net/nzw7LoL0/8 当我点击复选框 Paypal Id 标签中的贝宝时,它的文本框应该存在。剩下的 2 个文本框和标签应该隐藏。我够清楚了吗?
标签: javascript jquery html css