DOM3级事件中的键盘事件,不再包含charCode 属性,而是包含两个新属性:key 和char

2017-06-19 12:14:00
admin
原创
513
<!DOCTYPE html>
<html>
<head>
    <title>DOM Level 3 Key Property Example</title>
    <script type="text/javascript" src="http://code.ybao.org/demo/js/EventUtil.js"></script>
</head>
<body>
    <input type="text" id="myText" />
    <script type="text/javascript">
        var textbox = document.getElementById("myText");
        EventUtil.addHandler(textbox, "keyup", function(event){
            event = EventUtil.getEvent(event);

            var identifier = event.key || event.keyIdentifier;
            if (identifier){
                alert(identifier);    
            }      
        });
    </script>
</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络