How to prevent user from typing in text field without disabling the field?

前端 未结 11 1688
不思量自难忘°
不思量自难忘° 2021-01-31 06:58

I tried:

$(\'input\').keyup(function() {

   $(this).attr(\'val\', \'\');

});

but it removes the entered text slightly after a letter is enter

11条回答
  •  悲哀的现实
    2021-01-31 07:17

    if you don't want the field to look "disabled" or smth, just use this:

    onkeydown="return false;"
    

    it's basically the same that greengit and Derek said but a little shorter

提交回复
热议问题