javascript - Jquery:单击复选框时隐藏 slider

标签 javascript jquery html css

您好,我想在单击复选框时隐藏一些输入字段。

目前 checkbox 会在点击时改变颜色,这样我就知道哪个是事件的。单击时它不会隐藏该字段。

我已经尝试了几种方法,但似乎都不起作用,所以任何帮助都会很棒。

我的 JQuery 代码:

$(function () {
    $("#approvedToggle").buttonset(function () {
        if ($('#ApproveButton').prop('checked')) {
            $("#slider2").show();
        } else {
            $("#slider2").hide();
        }
    });
});

我的 asp.net 标记

<div class="price-slider">
     <h4 class="great">Do you pay an annual renewal fee?</h4>

    <div class="col-sm-12">
        <div>
            <fieldset id="approvedToggle" class="text-center">
                <input type="radio" id="ApproveButton" checked="checked" name="radio" />
                <label id="ApproveButtonLabel" for="ApproveButton">Yes</label>
                <input type="radio" id="RejectButton" name="radio" />
                <label id="RejectButtonLabel" for="RejectButton">No</label>
            </fieldset>
        </div>
        <p class="text-center">Percentage amount</p>
        <div id="slider2"></div>
         <h2 class="text-center" style="color: red"><b>OR</b></h2>

        <p class="text-center">Fixed Amount</p>
        <input type="text" id="fixedAnnualy" placeholder="0" class="form-control" />
        <br />
    </div>
</div>

我的 CSS

#ApproveButtonLabel.ui-state-active {
    background: blue;
}
#ApproveButtonLabel.ui-state-active span.ui-button-text {
    color: White;
    font: bold
}
#RejectButtonLabel.ui-state-active {
    background: blue;
}
#RejectButtonLabel.ui-state-active span.ui-button-text {
    color: White;
    font: bold
}

最佳答案

像这样尝试:

您需要更改事件操作并需要更改 html:

<div id="slider2"></div>

你的 $("#slider2") 是空的。

$(function () {
            $("#approvedToggle input[type='radio']").click(function () {
                if ($('#ApproveButton').prop('checked')) {
                    $("#slider2").show();
                } else {
                    $("#slider2").hide();
                }
            });
        });

demo

关于javascript - Jquery:单击复选框时隐藏 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23364872/

相关文章:

javascript - TypeError : _this. props.editAp 不是一个函数

javascript - 如何计算JavaScript中两个字符串中的公共(public)字符?

javascript - JQuery 获取链接并根据第 n 个数字添加变量

javascript - 将数据存储到 DOM - 元素值与数据属性

Javascript/JQuery : How do I count the words separated with a comma?

javascript - Trix 编辑器定义自定义附件样式

html - 最大宽度不适用于表格单元格

javascript - 使用javascript合并数组中的对象

javascript - 如何使用 HTML 和 Javascript 将表单结果发送到电子邮件?

javascript - 使用 jQuery Tablesorter 2.0 插件时如何禁用 thead 上的点击触发器?