简体   繁体   English

在输入文本字段中禁用键盘

[英]Disable Keyboard in Input Textfield

I have a jquery Datetimepicker and i want to disable the keyboard input. 我有一个jQuery Datetimepicker,我想禁用键盘输入。 I want only edit this field over the picker (Modalbox). 我只想在选择器(Modalbox)上编辑此字段。

You should disable keyboard on your input like this: 您应该像这样禁用输入的键盘:

$(function() {
   $('#datepicker').keypress(function(event) {
       event.preventDefault();
       return false;
   });
});

And Here is a working fiddle . 这是一个工作的小提琴

readonly attribute on the text input should work for you, use this property in input field either by manually entering or you can set this attribute using Javascript or jQuery. 文本输入上的readonly属性应该适合您,可以通过手动输入在输入字段中使用此属性,也可以使用Javascript或jQuery设置此属性。

Set a text field to read-only using Script: 使用脚本将文本字段设置为只读:

document.getElementById("myText").readOnly = true;

Or in HTML: 或使用HTML:

<input type="text" name="textName" placeholder="Select date" readonly>

Try this prop() 试试这个prop()

// Disable #x
$( "#x" ).prop( "disabled", true );

// Enable #x
$( "#x" ).prop( "disabled", false );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM