简体   繁体   English

我正在尝试在输入字段中禁用退格键

[英]I am trying to disable Backspace inside the input field

In this example I want to disable the backspace key on the input field.在此示例中,我想禁用输入字段上的退格键。

I am passing the $event in my template as:我将模板中的 $event 传递为:

<input (input)="onInput($event)">

while in my app.component.ts file the function is like this:而在我的 app.component.ts 文件中,function 是这样的:

onInput(e:KeyboardEvent){
if(e.keycode===8){
e.preventDefault();
}else{
console.log(e.which);
}

Also Typescript is complaining about e.keycode and e.which as being deprecated. Typescript 也在抱怨 e.keycode 和 e.which 已被弃用。

Edit: I forgot to add double quotes in the question on: (input)="onInput()"编辑:我忘了在问题中添加双引号: (input)="onInput()"

You have to change the output of input element from (input) to (keydown)您必须将输入元素的 output 从(input)更改为(keydown)

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

相关问题 我无法禁用输入字段 - I am unable to disable a input field 禁用键盘输入(不包括退格键) - Disable keyboard input excluding backspace 我正在尝试从 ReactJS 更新 Firestore 文档中的字段 - I am trying to update a field inside a document in Firestore from ReactJS 禁用并启用div内的下一个输入字段 - Disable and enable next input field that is inside a div 当我使用 useState 挂钩时,反应输入不起作用(输入字段内没有输入) - React input not working (there is no typing inside the input field) when I am using useState hook 我正在使用 select 搜索表单,我试图在输入文本字段中显示选定的值 - I am using select search form and i trying to display selected value in to the input text field 纯粹作为一个实验,我试图让除了在输入字段中输入更多数据之外绝对不可能做任何事情; 可行的? - Purely as an experiment, I am trying to make it absolutely impossible to do anything but enter more data into an input field; feasible? 在 ReactJS 待办事项应用程序中,我正在尝试将输入字段文本 state 设置为另一个 state 对象数组 - In ReactJS todo app I am trying to set input field text state into another state which is array of objects 在文本输入字段上模拟退格键 - simulate backspace key on text input field 退格键不会删除输入字段中的字母? - Backspace doesn't remove letters in the input field?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM