实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <title>Simulating IE Keyboard Events Example</title>
5
    <script type="text/javascript" src="/upload/files/201702/EventUtil.js"></script>
6
</head>
7
<body>
8
    <input type="text" value="" id="myTextbox" />
9
    <input type="button" value="Send keypress to the textbox" id="myBtn" />
10
    <p>This example works in IE though no text will appear in the textbox.</p>
11
    <script type="text/javascript">
12
    
13
    (function(){
14
        var btn = document.getElementById("myBtn");
15
        var textbox = document.getElementById("myTextbox");
16
        
17
        EventUtil.addHandler(textbox, "keypress", function(event){
18
            event = EventUtil.getEvent(event);
19
            var charCode = EventUtil.getCharCode(event);
20
            alert(charCode);
21
        });
22