对于我现在几乎工作,但唯一的事情是,当我隐藏项目item_35317
时,我也希望隐藏其余的标签(Zelfde als bij 'Uw gegevens'
和"Ander adres"
)
注意:我不能改变HTML中的任何内容,我只能用JS
或CSS
来改变它
也许有人知道我该如何隐藏这一切
$("input[name=item_35174][value='1']").prop('checked', true);
$("input[name='item_35174']").change(function() {
$("label[for=item_35317], input[type=radio][name=item_35317]").toggle(this.value == "0");
$("label[for=item_35175], input#item_35175").hide();
$("label[for=item_35176], input#item_35176").hide();
$("label[for=item_35177], input#item_35177").hide();
});
$("input[name='item_35174']:checked").change(); //trigger correct state onload
$("input[name='item_35317']").change(function() {
$("label[for=item_35175], input#item_35175").toggle(this.value == "1");
$("label[for=item_35176], input#item_35176").toggle(this.value == "1");
$("label[for=item_35177], input#item_35177").toggle(this.value == "1");
});
$("input[name='item_35317']:checked").change(); //trigger correct state onload
个字符
3条答案
按热度按时间jgovgodb1#
将你称之为标签的东西 Package 在一个span中,并给予它们和实际的标签一个类,然后使用元素的上下文来更改标签。
我使用了一个自定义事件来处理事情的表面。当我有更多的时间时,我会添加更多的解释。
编辑:关于自定义事件,我随机选择调用
hideShowMe
。我传递此事件一些自定义值ref:https://api.jquery.com/trigger/要通过这些:
$(this).trigger('hideShowMe', [isTrue, $showAssociates, $hideAssociates]);
然后在事件处理程序中使用它们:function(event, isTrue, $showAssociates, $hideAssociates)
,这是一种方法;还有其他几种方法,例如元素或数据属性上的类。然后我使用
.toggle()
,它传递了一个布尔值,当true时显示,当false时隐藏。然后,我在父“行”容器$showAssociates.closest('.mx_form_row').find('.toggle-label').toggle(isTrue);
中找到标签,并根据布尔值切换它们。注意我还做了一个初始的
trigger()
的变化事件,以设置显示的初始状态:字符串
关于收集元素引用的两个选择器:
型
实际上等同于
型
x759pob22#
字符串
vwkv1x7d3#
试试这个
个字符