- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在玩我的第一个 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/
哪些步骤会重现问题? 我想将这个“solo.searchButton("Show pictures");”用于当前屏幕上的搜索按钮。如果存在则执行一些操作,如果不存在则执行其他操作。 即使这个按钮不在
我正在玩我的第一个 PhoneGap/Android 应用程序,但无法从 PhoneGap/Cordova 事件触发 $.mobile.changePage()。 我已经更新了代码,而之前它只会触发一
我是一名优秀的程序员,十分优秀!