0

我在这里想要实现的只是应用更改同时breakoff应用更改thisjQuery('.toggle-bg')

jQuery 我试图只对breakofffrom 进行更改this .toggle-bg

    jQuery('.toggle-bg').on('change', function () {

    var value = jQuery('input.switch-id-value',this).val(),
    moon1 = jQuery('#' + value + '_0').is(':checked'),
    breakoff = jQuery('.line-break-off'),
    toggle = jQuery(this);

        toggle.css('background-color', (moon1 ? '#46b692' : '#333'));

        breakoff.each(function() {
            toggle.css('background-color', (moon1 ? '#46b692' : '#333'));
        });

}).trigger('change');

我确信有几件事可以使它起作用...我需要使用的示例.parent()让我向您展示 HTML,以便您了解breakoff与切换相关的位置。

HTML:

    <li class="top-header">

        <div class="box-title">
            <div class="section-icon fontawesome-twitter">
            <span class="line-decor"></span>
            <span class="line-break-off break"></span> //THE TARGET
            </div>
        </div>

// This is sloppy but this block below contains the toggle you get the idea.. 
// I dont have much experience using .parent() it kinda confuses me
// I am sure I need to nest my way out to target this.parent() .line-break-off

<div class="party">
    <div class="control-block ">
        <fieldset class="buttonset button-switch"><span class="toggle-bg" id="top-header" style="background-color: rgb(51, 51, 51);"><input type="radio" checked="checked" value="1" name="brashup[top-header]" id="top-header_0"><input type="hidden" value="top-header" class="switch-id-value"><input type="radio" value="0" name="brashup[top-header]" id="top-header_1"><input type="hidden" value="top-header" class="switch-id-value"><span class="switch ui-buttonset"><p class="switch-inner-bar"></p></span></span>
        </fieldset>&nbsp;&nbsp;
        <div class="bottom-box"><span class="description btn-desc">Here you can choose if you want a fixed header or not.</span>
        </div>
    </div>
</div>
</li>

简而言之,这是多个切换的列表,当特定切换发生更改时,我想.line-break-off通过添加一个类来操作它的父级,或者我可以从那里获取的任何 css :)

4

1 回答 1

1

尝试以下。breakoff应该是这样的:

breakoff = jQuery(this).parents(".top-header").find('.line-break-off')

接着:

breakoff.each(function() {
    jQuery(this).css('background-color', (moon1 ? '#46b692' : '#333'));
});
于 2013-09-07T22:23:44.123 回答