如何在 Windows Mobile 5 浏览器中检测 JavaScript 密钥事件

How to detect JavaScript key events in Windows Mobile 5 browser?

本文关键字:检测 JavaScript 密钥 事件 浏览器 Windows Mobile      更新时间:2023-09-26

我在网页上有一个文本框,按下回车键后,它应该会做一些事情。所以我检测了输入键的键代码。

我的问题是,似乎任何JavaScript键事件(按键,键下,键升)在Windows Mobile 5 IE浏览器中都不起作用?我也尝试过onlblur。我正在寻找一个理想的JavaScript解决方案。

我在网上看到一些关于将KeyPreview设置为true的建议,但这似乎仅适用于Windows Forms。

HTML 示例(似乎在除此情况外的情况下工作正常):

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
    function isEnterPressed(){
        if (window.event.keyCode == 13) {
                alert("Enter was pressed!");
            }
        }
</script>
</head>
<body onload="document.getElementById('txtEntry').focus();">
    <span>
        Press the enter key...if enter is detected, message will display below.
    </span>
    <br />
    <input type="text" id="txtEntry" onkeyup="isEnterPressed()">
</body>
</html>

如果这真的是Windows Mobile 5,则无法获取按键的JavaScript事件,因为Windows Mobile 5中的JScript不支持任何键事件。Javascript Key 事件支持始于 Windows Mobile 6(AKU 6.1.4 左右)。

有第三方"浏览器",如Intermec Browser,NaurTecc和zetakey,它们要么支持javascript密钥事件,要么使用特殊的META标签或浏览器"包装器"捕获的设置提供解决方法。