phonegap - 菜单按钮不会触发任何东西
我有以下代码来测试菜单按钮:
<script type="text/javascript" cahrset="utf-8">
//wait till device is ready
document.addEventListener("deviceready", onDeviceReady(), false);
//add a menu button event handler
function onDeviceReady() {
alert('deviceready');
document.addEventListener("menubutton", onMenuKeyDown(), false);
}
//fired when menubutton of device is clicked
function onMenuKeyDown() {
alert('menu key down');
}
</script>
但是当我按下菜单按钮时,没有任何反应。 Logcat 没有说什么,但我想因为这是来自标签“web console”,所以它可能很有用:
10-13 15:46:16.720: INFO/Web Console(13969): Error in success callback: Network Status1 = TypeError: Cannot read property 'apply' of undefined at :-2167
我从 Phonegap API 参考,但它似乎无法处理我的菜单按钮按下操作。 有什么帮助吗?预先非常感谢,丹尼尔
编辑:也许这对您了解发生了什么有帮助:当我按下菜单按钮时,logcat
10-18 09:21:52.560: WARN/WindowManager(152): statePower =normal
也显示,事件“searchbutton”也不起作用
I have the following code to test the menu button :
<script type="text/javascript" cahrset="utf-8">
//wait till device is ready
document.addEventListener("deviceready", onDeviceReady(), false);
//add a menu button event handler
function onDeviceReady() {
alert('deviceready');
document.addEventListener("menubutton", onMenuKeyDown(), false);
}
//fired when menubutton of device is clicked
function onMenuKeyDown() {
alert('menu key down');
}
</script>
however when I press them menu button, nothing happens. Logcat says nothing, but I guess since this is from tag "web console" it might be useful:
10-13 15:46:16.720: INFO/Web Console(13969): Error in success callback: Network Status1 = TypeError: Cannot read property 'apply' of undefined at :-2167
I followed this Tutorial from Phonegap API Reference but it doesnt seem to handle my menu button presses.
any help? thanks a lot in advance, daniel
edit: Maybe this is helpful for you to know whats going on: When I press the menu Button, logcat shows
10-18 09:21:52.560: WARN/WindowManager(152): statePower =normal
also, the event "searchbutton" doesnt work either
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,这似乎是听众的问题。通过在函数名称末尾添加括号,您可以在设置侦听器时立即调用该函数,而不是为稍后触发的事件设置引用。
尝试:
并且:
希望这有帮助!
From what I can see, it looks like an issue with your listeners. By adding the brackets at the end of the function name, you are invoking the function immediately when the listener is setup, instead of setting a reference for the event to fire later.
Try:
And:
Hope this helps!
检查您的body标签。确保它调用onload()函数。像这样:
Check your body tag. Ensure that it calls the onload() function. Like this:
好的,这个对我有好处
Ok, this one got good for me