可以更改可摺疊的小部件的特定主題類「亮點」吧,這裏有一個例子:
//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中看不到有任何衝突,但請注意,這是一條不必要的捷徑。
謝謝 - 它的工作很棒! – 2012-04-05 05:41:45