jquery(移动): use flip switch to change theme of collapsible cotent

标签 jquery mobile jquery-mobile

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

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

我想要一个视觉线索,表明选择了一个集合(开关隐藏在集合内,因此当关闭时,我不知道它是否被选择)

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

最佳答案

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

//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/

一些文档:

请注意,我创建的 classes 对象存储了两个用于 on 的类和两个用于 off 的类,这两个类都将被添加/删除使用 classes 对象时来自元素。我没有发现在 JSFiddle 中执行此操作有任何冲突,但请注意这是不必要的快捷方式。

关于jquery(移动): use flip switch to change theme of collapsible cotent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10012692/

相关文章:

javascript - 单击数据列表中的选项值后如何更改占位符文本

JavaScript 生成的元素不起作用 - jQuery

javascript - 如果第一个选择中的选项 1,则第二个选择被禁用

javascript - 我怎样才能在移动浏览器中隐藏一些div?并显示新的div。

android - Cocos2D-X文献

iOS 移动网络应用程序未更新

javascript - jQuery 的 remove() 绕过 FX 队列?我如何只在链的末端使用它?

javascript - 移动/平板设备方向部分工作

ruby-on-rails - Rails 4.0.0 jQuery Mobile 按钮图标未在生产中显示

css - jquery 移动 css 总是覆盖我的 css