1

我有一堆可折叠的集合,每个集合中都有一个用于发布数据的翻转开关。结果(有效)是

-itemA YES
-itemB NO
-itemC YES
...
-itemZ NO

我想有一个选择集合的视觉线索(开关隐藏在集合中,所以当关闭时,我不知道它是否被选中)

我发现我可以使用主题来更改外观,但是如何更改仅作为 switch 父级的可折叠集的主题。

4

1 回答 1

3

您可以更改可折叠小部件的特定主题类以“突出显示”它,这是一个示例:

//setup the classes and theme letters to use for on/off states
var classes = {
        on  : 'ui-btn-up-e ui-body-e',
        off : 'ui-btn-up-c ui-body-c'
    },
    themes  = {
        on  : 'e',
        off : 'c'
    };

//delegate the event handler binding for all toggle switches
$(document).on('change', '.ui-slider-switch', function () {

    //if the switch is "off"
    if ($(this).val() == 'off') {

        //find the parent collapsible widget of this switch, change its theme,
        //find the descendant header link and change it's theme attribute as well as class,
        //then go back to the collapsible selection and find the content wrapper
        //and change it's class to the "off" state class
        $(this).closest('.ui-collapsible').attr('data-theme', themes.off).find('a').attr('data-theme', themes.off).removeClass(classes.on).addClass(classes.off)
               .end().find('.ui-collapsible-content').removeClass(classes.on).addClass(classes.off);
    } else {

        //this does the same but backwards to make the "on" or active state
        $(this).closest('.ui-collapsible').attr('data-theme', themes.on).find('a').attr('data-theme', themes.on).removeClass(classes.off).addClass(classes.on)
               .end().find('.ui-collapsible-content').removeClass(classes.off).addClass(classes.on);
    }
});​

还有一个演示:http: //jsfiddle.net/ZtJyL/

一些文档:

Note that the classes object I created stores two classes for on and two for off, both of these classes will be added/removed from an element when using the classes object. I didn't see any conflict with doing this in my JSFiddle but just be aware that this is a shortcut that isn't necessary.

于 2012-04-04T17:08:14.597 回答