10

私のプロジェクトには、ブートストラップの日付ピッカーがまだ提供していないと思われる機能が必要です。ユーザーが値を変更できないように、datepicker フィールドを有効/無効にしたいと考えています。読み取り専用機能のようなもの。

それについてのアイデアはありますか?

前もって感謝します。

4

9 に答える 9

10
$("#nicIssuedDate").prop('disabled', true);

これは、 Bootstrap Datepicker と Jquery で機能します

于 2014-09-23T14:00:01.767 に答える
4

次のことができます。

無効にする場合:

$("#date").datepicker("option", "disabled", true);

そして有効にするために:

$("#date").datepicker("option", "disabled", false);

于 2015-12-07T16:23:08.923 に答える
1

オプション enabledDates を、表示したい日付のみの配列に設定してみてください。日付もその日付に設定します。他のすべての日付は無効になります。

enabledDates: ['your_date_to_show'],

例えば。

  $('#Date').datetimepicker({
    inline: true,
    viewMode: "days",
    format: "YYYY-MM-DD",
    enabledDates: [fetchDate("Date")],
  })
  .data("DateTimePicker")
  .date(fetchDate("Date"));

  $('#Date').ready(function (){
    $("#Date").data("DateTimePicker").date(fetchDate("Date"));
  });
于 2015-06-02T15:48:06.930 に答える
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)
            }]
        ];
    },
于 2014-03-27T11:05:46.640 に答える
-6

jquery attr メソッドを使用するだけです

$('').attr('disabled', true);

それで全部です :)

于 2014-06-04T16:33:33.330 に答える