单击按钮时尝试设置全局属性并将其存储在 $('html') 上,如下所示:
$('html'). attr('toggleIs',true);
然后您可以在pagebforeshow上检查这一点,并根据按钮状态将切换状态添加到所有被拉入视图的新页面上的按钮。
编辑
这是一个jsfiddle(忽略第一个警报);
这是html:
$(document).on('change', '.your_select', function(){
// set
if( $(this).find('option:selected').val() == "on" ){
$('html').data('toggle', 'on');
} else {
$('html').data('toggle', 'off');
}
});
$(document).on('pagebeforeshow', '.ui-page', function(){
var that = $(this).find('.your_select');
// clear
that.find('option').removeAttr('selected');
// reset
if($('html').data('toggle') == "on" ){
alert("should be on")
that.find('select option[value="on"]').attr('selected', 'selected')
} else {
alert("should be off")
that.find('option[value="off"]').attr('selected', 'selected')
}
// refresh slider
...
});
请注意:
- 我花了一段时间才看到你在哪里使用 jquery 1.6.4,所以我的绑定不起作用。如果要保留,则需要使用live进行绑定以捕获被拉入的页面。
- 我给所有的滑块上了一堂课,把它们放在一起
- 我无法让 JQM 滑块('refresh')在滑块或任何父元素上工作......你必须自己弄清楚,但同步正在工作:-)