【问题标题】:How disable ENTER keyboard interaction in datepicker [duplicate]如何在日期选择器中禁用 ENTER 键盘交互 [重复]
【发布时间】:2016-03-04 11:12:48
【问题描述】:

这里: http://api.jqueryui.com/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 键不得在我的字段中设置日期。我的 Enter 键必须在该字段中执行其他操作(确实如此),只是不想在该字段中设置日期。

【问题讨论】:

  • 尝试添加$('.className').on('keypress', function(e) { if(e.keyCode == 13) { return false; } });

标签: javascript jquery html jquery-ui datapicker


【解决方案1】:

试试这个,

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多