如何在文本输入字段中禁用手动输入 - JQuery Datepicker

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16799877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:49:33  来源:igfitidea点击:

how can I disable manual inputs in the text input field- JQuery Datepicker

jqueryjquery-ui

提问by user2395176

I have a text box and I can able to find the ID of that textbox. Binded a JQuery date picker to that text box. My requirement is the user can select the values only through Datepicker. User can't enter value manually. Is it possible?

我有一个文本框,我可以找到该文本框的 ID。将 JQuery 日期选择器绑定到该文本框。我的要求是用户只能通过 Datepicker 选择值。用户不能手动输入值。是否可以?

Any help is very ppreciated!

非常感谢任何帮助!

回答by Nikola Mitev

make the textbox readonly

使文本框只读

<input type="text" size="23" id="dateMonthly" readonly="readonly" style="background:white;" />

or via jquery

或通过 jquery

$('#dateMonthly').attr('readonly', true);

回答by Smeegs

Add "readonly" to the tag.

将“只读”添加到标签中。

  <input type="text" name="date"  readonly>

回答by kayz1

Try something like this:

尝试这样的事情:

HTML

HTML

<input class="date-input" type="text" readonly="readonly" />

CSS

CSS

.date-input {
      background-color: white;
      cursor: pointer;
}

回答by Updesh Srivastava

Readonly or disabled does not work for me atleast.

只读或禁用至少对我不起作用。

We can override the key events on the input control

我们可以覆盖输入控件上的按键事件

<input onkeydown="return false" ... />