如何在datepicker中禁用ENTER键盘交互

时间:2016-03-04 11:12:49

标签: javascript jquery html jquery-ui datapicker

下面: http://api.jqueryui.com/datepicker/ 我明白了:

  

键盘互动

     

当datepicker打开时,以下键命令是   可用的:

PAGE UP: Move to the previous month.
PAGE DOWN: Move to the next month.
CTRL + PAGE UP: Move to the previous year.
CTRL + PAGE DOWN: Move to the next year.
CTRL + HOME: Open the datepicker if closed.
CTRL/COMMAND + HOME: Move to the current month.
CTRL/COMMAND + LEFT: Move to the previous day.
CTRL/COMMAND + RIGHT: Move to the next day.
CTRL/COMMAND + UP: Move to the previous week.
CTRL/COMMAND + DOWN: Move the next week.
ENTER: Select the focused date.
CTRL/COMMAND + END: Close the datepicker and erase the date.
ESCAPE: Close the datepicker without selection.

我不想要:

  

ENTER:选择聚焦日期。

相互作用

是否可以禁用单个互动?我在特定字段中的Enter键不能在我的字段上设置日期。我的回车键必须在该字段中执行其他操作(确实如此),甚至不想在字段中设置日期。

1 个答案:

答案 0 :(得分:0)

试试这个,

$(document).ready(function() {
    $("#myDate").datepicker().on("keydown", function(e){
        if (e.which == 13) {
            $("#myDate").val('');
            return false;
        }
    });
});