Asp.net-Mvc

使用 bootstrap-datepicker 時如何不顯示移動鍵盤?

  • August 7, 2021

我嘗試設置該disableTouchKeyboard選項,但它什麼也沒做——至少在 iOS/Safari 上是這樣。我專門使用的選項是:

$(".datepicker").datepicker({
   autoclose: true,
   disableTouchKeyboard: true,
   format: 'm/d/yyyy',
   startDate: '01/01/1900',
   todayBtn: 'linked',
   todayHighlight: true,
});

有誰知道最好的方法是什麼?

這就是我完成此任務的方式,但我很想知道是否有更好的方法。

在問題中使用相同的選項,然後我還通過在我的 HTML 中執行此操作來製作 HTML 文本框readonly

@Html.EditorFor(model => model.Date, new { htmlAttributes = new { 
   @class = "form-control datepicker", @readonly = "true",
}})

這似乎可行,因為 JavaScript 仍然可以更改欄位的值。但是,它確實使文本框的背景變為灰色(即禁用),並將滑鼠指針更改not-allowed為不需要的交叉圓圈圖示 ( )。為了解決這個問題,我添加了一個內聯樣式:

@Html.EditorFor(model => model.Date, new { htmlAttributes = new { 
   @class = "form-control datepicker", @readonly = "true",
   style = "cursor: default; background-color: #fff"
}})

我試圖覆蓋 CSS 中的cursorand background-color(使用!important),但這似乎在 Internet Explorer 中不起作用。

這不漂亮,但對我有用。仍然需要看看我如何以更強大的方式做到這一點(例如,沒有硬編碼背景顏色,不必在我的所有日​​期欄位中指定它等)。如果有人知道更好的方法,我將非常感激。

如果您使用的是 Bootstrap3 日期選擇器:
https ://eonasdan.github.io/bootstrap-datetimepicker

只需將此屬性添加到輸入中:readonly=“readonly” 並將此屬性
添加到實例化庫時的選項中。

$('#datetimepicker1').datetimepicker({
       useCurrent: false,
       daysOfWeekDisabled: [0, 6],
       format: 'DD-MM-YYYY',
       ignoreReadonly: true   <------ this property
});

在 Safari iPhone 和 Chrome / Native 瀏覽器 Android 上測試。

引用自:https://stackoverflow.com/questions/29591956