当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Bootstrap datepicker: hide calendar on enter key press

问题描述:

How can I hide bootstrap datepicker calendar on enter keypress? I know it has autoClose option but that's not what I want.

网友答案:

This link can help you fix for pressing enter after, manually entering the date

网友答案:

Something like this might help you

$('#date-selected').keydown(function (ev) {
var keycode = (ev.keyCode ? ev.keyCode : ev.which);
if (keycode == '13') {
    var dp = $('#date-picker').data('datepicker');
    // 1: we manually restore the input date so it's not toggled on/off
    dp.dates.pop(); // idempotent if no dates
    dp.dates.push(dp.viewDate);
    dp.setValue();
    // 2: we move to the next input field & close the picker
    $('input[id!="date-selected"]').first().focus();
    dp.hide();
    }
});

Reference:- https://chezsoi.org/lucas/blog/2014/10/27/en-overriding-the-enter-keydown-behaviour-in-bootstrap-datepicker-js/

网友答案:

following code worked for me, posting answer to my own question to help other

$(".datepicker").datepicker('hide');
分享给朋友:
您可能感兴趣的文章:
随机阅读: