[Ext.Net]Class Ext.KeyMap

来源:互联网 发布:腾讯游戏数据分析师 编辑:程序博客网 时间:2024/05/16 15:04

Class Ext.KeyMap

Package:ExtClass:KeyMapExtends:ObjectDefined In:KeyMap.js
Handles mapping keys to actions for an element. One key map can be used for multiple actions. The constructor accepts the same config object as defined byaddBinding. If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key combination it will call the function with this signature (if the match is a multi-key combination the callback will still be called only once): (String key, Ext.EventObject e) A KeyMap can also handle a string representation of keys.
Usage:
// map one key by key code var map = new Ext.KeyMap("my-element", {     key: 13, // or Ext.EventObject.ENTER     fn: myHandler,     scope: myObject });  // map multiple keys to one action by string var map = new Ext.KeyMap("my-element", {     key: "a\r\n\t",     fn: myHandler,     scope: myObject });  // map multiple keys to multiple actions by strings and array of codes var map = new Ext.KeyMap("my-element", [    {        key: [10,13],        fn: function(){ alert("Return was pressed"); }    }, {        key: "abc",        fn: function(){ alert('a, b or c was pressed'); }    }, {        key: "\t",        ctrl:true,        shift:true,        fn: function(){ alert('Control + shift + tab was pressed.'); }    }]);
Note: A KepMap starts enabled


官方DEMO

http://examples1.ext.net/#/Keys/KeyMap/BorderLayout_Regions_Toggle/

http://examples1.ext.net/#/Keys/KeyNav/Basic/

http://examples1.ext.net/#/Keys/Panel_Keys/Grid_Rows_Delete/

我们来试试文本框回车和鼠标移开。

    <script>        function KeyUp(field, e) {            if (e.getKey() == Ext.EventObject.ENTER)                alert("回车键已被按下");        }        var  Move=function(){                alert("鼠标已被移开");        }    </script>
        <ext:TextField ID="txtKeyWord" Width="200" runat="server" FieldLabel="回车键">            <Listeners>                <SpecialKey Fn="KeyUp" />            </Listeners>        </ext:TextField>        <ext:TextField ID="TextField1" Width="200" runat="server" FieldLabel="鼠标移开">            <Listeners>                <Blur Fn="Move" />            </Listeners>        </ext:TextField>

测试结果成功:

原创粉丝点击