jquery - jquery 中的淡入和淡出?

标签 jquery checkbox radio-button fadein fadeout

我想在同一个 jQuery 中使用 .fadeIn().fadeOut() 来实现两个不同的函数。

例如:想象一个表单

假设以下是单选按钮:

O U.S. - 如果我选择美国,它会淡出 - 美国的城市/省份 O 加拿大。- 如果我选择加拿大,它会淡入 - 美国的城市/省份

另一个单选按钮://这与上面的单选按钮(美国,加拿大)之间没有关系

O Male - 它应该在酒吧、酒吧等地方淡出 O 女性-它应该在商场、水疗中心等处褪色

我该如何使用jquery?

最佳答案

jsFiddle Demo

如果我理解得好,这应该符合您的需求。

HTML

    <input type="checkbox" id="group1Switch" value="group1" /><label for="group1Switch">group 1</label>
&nbsp;&nbsp;&nbsp;
<input type="checkbox" id="group2Switch" value="group2" /><label for="group2Switch">group 2</label>
<br /><br />
<input type="radio" name="fieldSwitch" id="type1Switch" value="type1" /><label for="type1Switch">type 1</label>
&nbsp;&nbsp;&nbsp;
<input type="radio" name="fieldSwitch" id="type1Switch" value="type2" /><label for="type1Switch">type 2</label>

<br /><br />

<fieldset id="group1">
    <legend>Group 1</legend>
    type 1 <input type="text" class="type1" />
    <br />
    type 2 <input type="text" class="type2" />
</fieldset>
<fieldset id="group2">
    <legend>Group 2</legend>
    type 1 <input type="text" class="type1" />
    <br />
    type 2 <input type="text" class="type2" />
</fieldset>

jQuery

$('input[type=checkbox]').click(function(){
    var _this = $(this);

    if( _this.is(':checked') ){
        $('#' + _this.val() ).fadeIn();
    } else {
        $('#' + _this.val() ).fadeOut();
    }
});


$('input[type=radio]').click(function(){
    var _this = $(this);

    $('fieldset input.' + _this.val() ).fadeIn();
    $('fieldset input:not(.' + _this.val() +')' ).fadeOut();
});

关于jquery - jquery 中的淡入和淡出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5391751/

相关文章:

java - 通过菜单子(monad)项 onclick 更改 textview 的字体

jquery - 不是选择器, on() 点击事件不起作用

javascript - 在javascript中获取触摸的持续时间

javascript - 元素上的 jQuery touchSwipe 事件阻止滚动

html - HTML/CSS 中的单选/复选框对齐

javascript - 根据条件禁用复选框

不需要 WordPress 联系表 7 radio

java - ListView 中 RadioGroups 中的其他按钮被选中

javascript - 如何让按钮点击后凹陷?

checkbox - 如何使用 React Hook Forms Field Array 从服务器设置动态数组的复选框值