修改键

2017-06-19 11:50:00
admin
原创
530
<!DOCTYPE html>
<html>
<head>
    <title>Modifier Keys Example</title>
    <script type="text/javascript" src="http://code.ybao.org/demo/js/EventUtil.js"></script>
</head>
<body>
    <div id="myDiv" style="background-color:red;height:100px;width:100px">Click me while holding a modifier key</div>
    <script type="text/javascript">
        var div = document.getElementById("myDiv");
        EventUtil.addHandler(div, "click", function(event){
            event = EventUtil.getEvent(event);
            var keys = new Array();
        
            if (event.shiftKey){
                keys.push("shift");
            }
        
            if (event.ctrlKey){
                keys.push("ctrl");
            }
        
            if (event.altKey){
                keys.push("alt");
            }
        
            if (event.metaKey){
                keys.push("meta");
            }
        
            alert("Keys: " + keys.join(","));
        
        }); 

    </script>
</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络