【发布时间】:2012-05-27 21:44:13
【问题描述】:
我一无所知。
在我的 Jquery 移动插件中,我声明:
var $currentEntry = $.mobile.urlHistory.stack[$.mobile.urlHistory.activeIndex].url;
$activePage = $('div:jqmData(url="'+ $currentEntry +'")');
所以我正在获取活动页面的 url 并使用它来构造一个 $activePage 对象。
这在桌面上运行良好,但在我的 iPad (iOS3.3) 上,$currentEntry 定义正确,但 $activePage 是 未定义.
问题:
这可能是什么原因?
您可以排除竞争条件,因为将其包装在 10 秒超时中仍会产生相同的结果。此外,如果我直接控制相应页面并查询它的 data-url,它会显示正确的值。那么为什么上面仍然给我在 iOS 上 undefined
undefined
同时在其他地方正常工作?
感谢任何提示!
编辑:
该元素将是动态的,但我可以直接在我的设置中对页面进行控制台,如下所示:
console.log( $('div:jqmData(wrapper="true").ui-page-active').attr('id') );
console.log( $('div:jqmData(wrapper="true").ui-page-active').attr('data-url') );
都返回正确的id和data-url,所以元素必须存在。
EDIT2:
我可以查询属性 data-url 给我正确的值。但是,我不能像这样选择使用这个属性:
$('div[data-url="'+$currentEntry+'"]').length
这给了我0
【问题讨论】:
-
那么,您要查找的 HTML 元素是否存在?
-
可能不是问题,但你知道
$activePage是一个全局变量吗? -
@AndrewWhitaker - 好点!也在检查。
-
可能是
:jqmData(url="...")选择器在 iPad 上不起作用... -
@ŠimeVidas - 嗯...我不喜欢这个数据网址。让我们试试 attr()
标签: javascript jquery variables web-applications undefined