Bootstrap datepicker禁用功能

Jua*_*uis 10 datepicker twitter-bootstrap

我需要在我的项目中使用一个功能,我认为bootstrap datepicker仍然没有提供.我想启用/禁用datepicker字段,以便用户无法更改其值.类似于readOnly功能.

关于它的任何想法?

先感谢您.

Chi*_*asa 10

$("#nicIssuedDate").prop('disabled', true);
Run Code Online (Sandbox Code Playgroud)

这适用于 Bootstrap Datepicker和Jquery


Jua*_*uis 0

我找到了解决方案,但只需修改引导日历代码即可。覆盖 this._events 部分以禁用 keyup/down 事件对我有用:

_buildEvents: function(){
        if (this.isInput) { // single input
            this._events = [
                [this.element, {
                    focus: $.proxy(this.show, this),
                    keyup: $.proxy(this.update, this),
                    keydown: $.proxy(this.keydown, this)
                }]
            ];
        }
        else if (this.component && this.hasInput){ // component: input + button
            this._events = [
                // For components that are not readonly, allow keyboard nav
                [this.element.find('input'), {
                    //focus: $.proxy(this.show, this),
                    //keyup: $.proxy(this.update, this),
                    //keydown: $.proxy(this.keydown, this)
                }],
                [this.component, {
                    click: $.proxy(this.show, this)
                }]
            ];
        }
        else if (this.element.is('div')) {  // inline datepicker
            this.isInline = true;
        }
        else {
            this._events = [
                [this.element, {
                    click: $.proxy(this.show, this)
                }]
            ];
        }

        this._secondaryEvents = [
            [this.picker, {
                click: $.proxy(this.click, this)
            }],
            [$(window), {
                resize: $.proxy(this.place, this)
            }],
            [$(document), {
                mousedown: $.proxy(function (e) {
                    // Clicked outside the datepicker, hide it
                    if (!(
                        this.element.is(e.target) ||
                        this.element.find(e.target).length ||
                        this.picker.is(e.target) ||
                        this.picker.find(e.target).length
                    )) {
                        this.hide();
                    }
                }, this)
            }]
        ];
    },
Run Code Online (Sandbox Code Playgroud)