【发布时间】:2013-08-07 22:58:13
【问题描述】:
我似乎在以编程方式打开和关闭 JQM 1.3 面板时遇到问题。
编辑:这是针对 JQM 1.3.x 而不是 1.4+
这有点难以解释,所以我只是做了一个小提琴:)
有很多事情发生了,但这只是一个更大的应用程序的示例,并传达了问题。
如何复制:
- 去小提琴
- 在 Fiddle 打开面板并转到第二页
- 在第二页打开面板并转到第一页
- 现在尝试在第一页打开面板,它什么也没做。
受影响的浏览器:
编辑:这似乎已在 Chrome 30.0.1599.101 m 中修复
- 铬 28.0.1500.95 m
- IE 10.0.9200.16635
- Safari // 最新版本
- Android WebView (4.2.2)
浏览器不受影响:
- 火狐23
- Opera 12.16
Fiddle 链接:
链接到其他帖子
https://github.com/jquery/jquery-mobile/issues/6308
http://forum.jquery.com/topic/panel-not-responding-after-page-change
编辑: 所以 Firefox 给了我一个 Chrome 或 IE 都没有的错误。
当我点击返回第一页时,我得到:
Type Error: elem is undefined
这个错误是JQ 1.9.1抛出的,我追到这个:
A method for determining if a DOM node can handle the data expando
acceptData: function( elem ) {
// Do not set data on non-element because it will not be cleared (#8335).
if ( elem.nodeType && elem.nodeType !== 1 && elem.nodeType !== 9 ) {
return false;
}
var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ];
// nodes accept data unless otherwise specified; rejection can be conditional
return !noData || noData !== true && elem.getAttribute("classid") === noData;
}
`
注意:
不要在非元素上设置数据,因为它不会被清除(#8335)。
Github 问题链接: https://github.com/jquery/jquery/pull/1232
OG 代码:
$('.showMenu').on('click', function(){
$.mobile.loading('hide');
$.mobile.activePage.find('#'+$.mobile.activePage.attr('id')+'P').panel("toggle");
});
$('.btnMenuItem').on('click', function(event){
myPgActions.nav(event, function(target){
$.mobile.changePage(target);
}, false);
});
var myPgActions = {};
myPgActions = {
nav: function(event, callback, manualHash){
var PID = $.mobile.activePage.attr('id'),
target = (!!event) ? event.target.name : manualHash;
$("#"+PID+"P").panel( "close" );
if(PID != 'loading') $("#"+PID+"Iframe").hide();
if(PID == target){
$("#"+PID+"Iframe").hide('fast', function(){
$("#"+PID+"Iframe").attr('src', "");
myPgActions.update(PID, target, 'refresh', function(target){
callback(target)
});
});
}else{
this.update(PID, target, 'change', function(target){
callback(target);
});
}
},// end get
update: function(PID, target, type, updateCallback){
var ifReady = $.Deferred();
if(type == 'refresh'){
this.buildUrl(PID, function(url){
$('#'+PID+'Iframe').attr( 'src', url);
ifReady.resolve();
$.when(ifReady).then(function(){
updateCallback('#'+PID+'Iframe')
});
});
}else if(type == 'change'){
this.buildUrl(target, function(url){
$('#'+target+'Iframe').attr( 'src', url);
ifReady.resolve();
});
$.when(ifReady).then(function(){
updateCallback('#'+target);
});
}
}, // end set
buildUrl: function(page, buildCallback){
switch(page){
case 'dash':
var mobileSiteUrl = 'URL with options for iframe'
setTimeout(function(){buildCallback(mobileSiteUrl);},25);
break;
case 'local':
var mobileSiteUrl = 'URL with options for iframe'
setTimeout(function(){buildCallback(mobileSiteUrl);},25);
break;
}// End Switch
}
}// End Obj
【问题讨论】:
-
你应该使用
.panel('open')和.panel('close')而不是隐藏和切换。 -
如果您使用的是 JQM 1.4alpha1,则面板小部件中存在一个错误,这也可以解释您的问题
-
@Omar 这里是使用打开和关闭的分叉小提琴,但我有相同的结果。 jsfiddle.net/XhupG
-
将 Safari 添加到受影响的浏览器。
-
Android WebView (4.2.2) 上的同样问题
标签: javascript jquery jquery-mobile