在 Blackberry 上使用 Javascript 进行 KeyUp
我目前正在开发一个专为浏览器和移动设备设计的网页,但在使用黑莓时遇到了问题
。我想要的功能是在按下按键时触发弹出窗口。我当前的代码可以在浏览器中运行,但不能在黑莓上运行。我在运行 OS 5.0 的黑莓模拟器上启用了 javascript 和 javascript 弹出窗口。
最初的调用:
window.onkeyup = GetKeyUp;
然后是方法:
function GetKeyUp(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
alert(KeyID);
}
什么在黑莓上不起作用而在浏览器中起作用? 或者:
如何从 JavaScript 捕获黑莓上的按键?
谢谢, Ty
最新开发:使用“window.addEventListener("keyup",...)”或 “document.addEventListener(“keyup”,...)”则不起作用。
I am currently developing a web page designed for browsers and mobile devices and am having trouble with blackberry's
The functionality I want is to trigger a popup when a key is pressed. My current code works in browser, but not on the blackberry. I have javascript and javascript popups enabled on my blackberry emulator which is running OS 5.0.
The initial call:
window.onkeyup = GetKeyUp;
And then the method:
function GetKeyUp(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
alert(KeyID);
}
What is not working on Blackberry that would work in browser?
Or alternatively:
How do I capture key presses on a blackberry from javascript?
Thanks,
Ty
NEWEST DEVELOPMENT: Using "window.addEventListener("keyup",...)" or
"document.addEventListener("keyup",...)" instead does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
奇怪...我会尝试一些事情:
确保在 Blackberry 上启用 Javascript(默认情况下通常禁用)。
尝试使用
.charCode
而不是.keyCode
尝试使用
document.onkeyup
而不是window.onkeyup
Strange... Some things I'd try:
Ensure that Javascript is enabled on the Blackberry (it's usually disabled by default).
Try using
.charCode
instead of.keyCode
Try using
document.onkeyup
instead ofwindow.onkeyup
黑莓似乎在 JavaScript 方面遇到了一些困难。
如果你可能的话,我建议你使用一个库(比如 JQuery )。通常这些类型的库是为了与 xbrowser 兼容而设计的,它们会为您完成兼容性工作。
如果您必须保留纯 JavaScript 代码,请尝试在 GetKeyUp 函数中添加一个alert(),以查看 onkeyup 事件是否被识别。
Blackberry seems to have some difficulties with javascript.
If it's possible for you, I would suggess that you go with a library ( like JQuery ). Usually theses kind of library are made to be xbrowser compatible, they do the compatibility work for you.
If you must remain with pure javascript code, try to put an alert() in you GetKeyUp fonction to see if the onkeyup event is recognized.