繁体   English   中英

在jQuery中选择具有自定义样式的复选框

[英]select checkbox with custom styling in jquery

我的jQuery中有一个复选框作为选择器。 选中此复选框时,应该为另一个div元素设置css类。 我的问题是jQuery不响应:checked参数

我得到了:

jQuery的

    $(function () {
        if ($('#tab').is(':checked')) {
            $(".choices").attr({ "visibility": "visible" });
            $(".question1").attr({ "border-bottom-left-radius": "0px" })
        }
        else {
            $(".choices").removeAttr('style');
            $(".question1").removeAttr('style');
        };

HTML

                    <label>
                    <input type="checkbox" name="check" id="tab" /><span class="label-text">Valgmuligheder</span>
                    </label>

我的自定义复选框的意思是,我为该框使用了字体,而不是最初的样式。 但是,初始复选框仅被隐藏,并且与字体一起被选中。

我猜我的代码在选择器中失败了,但是我似乎无法正确选择它。

请尝试使用以下JS,但要进行登录,请根据需要进行更新-

  $('input[type=checkbox]').change(function(){ if ($('#tab').is(':checked')) { alert('hii'); $(".choices").attr({ "visibility": "visible" }); $(".question1").attr({ "border-bottom-left-radius": "0px" }) } else { $(".choices").removeAttr('style'); $(".question1").removeAttr('style'); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label> <input type="checkbox" name="check" id="tab" /><span class="label-text">Valgmuligheder</span> </label> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM