jQuery UI datepicker: Configure keyboard shortcuts

前端 未结 4 577
隐瞒了意图╮
隐瞒了意图╮ 2021-02-07 17:56

I use the jQuery UI datepicker to let the user select a date. It has some shortcuts so that it can be controlled using the keyboard:

page up/down      - previous         


        
4条回答
  •  爱一瞬间的悲伤
    2021-02-07 18:34

    If you want to replace one of the shortcuts and do not like coping the code from the repository in case of updating the jquery ui library, use:

    // original key down callback
    var doKeyDown = $.datepicker._doKeyDown;
    $.extend($.datepicker, {
        _doKeyDown: function(event){
    
            if(event.which !== $.ui.keyCode.ENTER) {
                doKeyDown(event);
            }
            else {
                //do something else
            }
        }
    });
    

    Keep a reference of _doKeyDown before you overwrite it and call it for all other shortcuts.

提交回复
热议问题