简体   繁体   English

我想在输入字段中只接受 1-24 并禁用所有其他按钮。 这怎么可能

[英]I want to accept only 1-24 in the input field and disable all other buttons. how is it possible

This is my input field and I want to accept only 1-24 and disable all other keys.这是我的输入字段,我只想接受 1-24 并禁用所有其他键。 How can this be achieved in react.如何在反应中实现这一点。

                    <TextFieldCustom
                    placeholder="Enter checkin hours"
                    value={e.target.value}
                    onChange={onChangeHandler}
                    maxLength={3}
                    type=number
                    onKeyDown={onKeyDown}
          
                  />

here is the change handler of your case without specifying type="number" :这是您的案例的更改处理程序,但未指定 type="number" :

const [text, setText] = useState('');
  const changeHandler = (e: any) => {
    const val = e.target.value;
    if ((val >=1 && val <= 24) || val === '') {
      setText(val);
    }
  };

return (
 <TextFieldCustom
   placeholder="Enter checkin hours"
   value={text}
   onChange={changeHandler}
   onKeyDown={onKeyDown}
  />
);

暂无
暂无

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

相关问题 我想单击框上的任何位置以将我导航到除按钮之外的帖子详细信息页面。 它的按钮应该是它自己的工作 - I want to click anywhere on the box to navigate me to the post detail page except the buttons. It's buttons should it's own job 如何仅禁用带有复选框的输入字段? - How to disable only a input field with checkbox? 如何将输入字段和按钮向上对齐,使其与其他按钮对齐? - How would I align my input field and button upward to make it inline with other buttons? 我如何只启用一个按钮 onclick 并使用 react js 禁用所有其他按钮 - how i can enable only one button onclick and disable all other using react js 只需要在输入字段中接受数字 - need to accept only numbers in the input field 我想禁用此日期选择器的键盘输入,该怎么做? - I want to disable keyboard input for this date picker how to do that? 这是我必须通过各种按钮显示信息的代码。 问题是当我单击一个按钮时,其他按钮会显示信息 - Here is code where I have to display information through various buttons. The issue is that when I click one button, the other buttons display info 仅当特定输入为空时,如何禁用按钮? - How can I disable a button only if specific Input is empty? 我在一个组件中同时使用两个按钮,当我单击它而不是另一个按钮时,我只希望一个按钮起作用 - i am using two buttons simultaneously in one component, i want only one button to work when i click it not the other button 单击按钮后,如何将按钮中的文本输入到警报中? (以及如何禁用和保持选中按钮) - Upon clicking a button, how can I input the text from the button into an alert? (And how to disable and leave buttons selected)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM