解决easyUI下拉控件无法触发onkeydown事件

实现在combotree下拉控件中按Backspace键清除combotree选中的值

下面的代码无法获取到键盘事件

<input class="easyui-combotree" id="tt" name="tt" onkeydown="if(event.keyCode==8) clear()"/>

 原因是easyUI重新定义了键盘事件,解决如下:

$("#tt").combotree({
        url: '../insurance/getcalInsuranceList.do',
        valueField: 'id',
        textField: 'text',
        editable: true,
        lines:true,
        onlyLeafCheck:true,
        panelHeight: 'auto',//高度
        keyHandler: {
          query: function(q,e){
            //q 为输入框的文本值
            if(e.keyCode==8){
              $("#tt").combotree('clear')
              $('#tt').combotree('hidePanel');
            }
          }
        },
        onLoadSuccess : function() {
            $("#tt").combotree('tree').tree("collapseAll");//折叠所有节点
        },
        onBeforeSelect: function(node) {
          if (!$(this).tree('isLeaf', node.target)) {
            $(this).tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);  
            return false;
          }
        },
        onClick: function(node) {  
          if (!$(this).tree('isLeaf', node.target)) {  
              $('#tt').combotree('showPanel');  
          }  
        }  
      });

  

posted @ 2017-05-17 18:54  阿龙阿  阅读(601)  评论(0编辑  收藏  举报