gpt4 book ai didi

cordova - .live ("pageshow"..) 不适用于 Phonegap JQuery Mobile

转载 作者:行者123 更新时间:2023-12-04 17:37:31 25 4
gpt4 key购买 nike

我有以下使用 JQuery Mobile 的代码。这里的要点是我希望在触发 'pageshow' 事件时执行一些代码。

下面的所有代码在 Chrome 上运行良好。我可以看到控制台日志。但是,当我将它作为 Phonegap 应用程序的一部分运行时,我永远不会触发“pageshow”事件。

已经对此进行了一段时间的调查,但没有成功。希望有人能解释我为什么我的事件丢失以及需要哪些步骤才能使此代码在 Phonegap 上运行。

详情.html

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"> </script>
<link rel="stylesheet" href="css/index.css" />
<!-- cordova -->
<script src="cordova-2.2.0.js"></script>
</head>
<body>
<div data-role="page" id="details_page">
<a href="places.html" data-transition="slide" data-direction="reverse">Back</a>
<h3>Hi I am second page</h3>
</div>

<script src="js/details.js"></script>

</body>
</html>

details.js
$("#details_page").live("pageshow", function() {
console.log('I am alive! (details.html)');
});

最佳答案

你应该使用以下

$(document).delegate("#details_page", "pageshow", function() {
console.log("Hello world!");
});

另请注意,您只能在触发 deviceready 事件后运行代码。

因此,对于设备就绪事件,它会是这样的:
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
$(document).delegate("#details_page", "pageshow", function() {
console.log("Hello world!");
});
}

希望这可以帮助,
麦克风

关于cordova - .live ("pageshow"..) 不适用于 Phonegap JQuery Mobile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13840982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com