简体   繁体   中英

Disable Keyboard in Input Textfield

I have a jquery Datetimepicker and i want to disable the keyboard input. I want only edit this field over the picker (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.

Set a text field to read-only using Script:

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

Or in HTML:

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

Try this prop()

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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