gpt4 book ai didi

javascript - PhoneGap 1.5 "menubutton"和 "searchbutton"与 jQuery Mobile

转载 作者:行者123 更新时间:2023-11-29 18:12:49 24 4
gpt4 key购买 nike

我正在玩我的第一个 PhoneGap/Android 应用程序,但无法从 PhoneGap/Cordova 事件触发 $.mobile.changePage()

我已经更新了代码,而之前它只会触发一次。现在它根本不会触发,但更接近它可能应该如何完成。

这是我的代码:

    $(document).on('pageinit', function() {
document.addEventListener("searchbutton", onSearchKeyDown, false); //never fires
document.addEventListener("menubutton", onMenuKeyDown, false); //never fires
alert("triggered"); //does fire
});

// search button press
function onSearchKeyDown() {
//change to search page
alert("search");
$.mobile.changePage("#page4", {transition: "pop"});
}

//menu button press
function onMenuKeyDown() {
//change to start page
alert("menu");
$.mobile.changePage("#page1", {transition: "pop"});
}

最佳答案

使用pageInit(),而不是$(document).ready()

参见文档 here :

The first thing you learn in jQuery is to call code inside the $(document).ready() function so everything will execute as soon as the DOM is loaded. However, in jQuery Mobile, Ajax is used to load the contents of each page into the DOM as you navigate, and the DOM ready handler only executes for the first page. To execute code whenever a new page is loaded and created, you can bind to the pageinit event. This event is explained in detail at the bottom of this page.

关于javascript - PhoneGap 1.5 "menubutton"和 "searchbutton"与 jQuery Mobile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9775295/

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