如何拒绝用户输入的额外字符?
在我的html中,我有一系列输入。应允许用户在每个字符中输入一个字符。这是其html:
&lt; input class =“ green” type =“ text” maxlength =“ 1” /&gt; < /code>
css的CSS如下:
input {
font: 1.5em "Times New Roman", Times, serif;
width:0.9em; height: 0.9em;
text-align:center; }
.green {
color: green; }
如果用户输入角色,然后tries tries要输入另一个,什么都不会发生。但是,在我的设计中,用户可以输入任何数量的字符,即使将较早的字符推向左侧,只有最后一个字符才能看到。当焦点离开输入字段时,所有额外的字符都会消失,并且仅保留第一个输入字符。我如何确保当用户尝试输入其他字符时,它们会被忽略而什么都不会发生?
In my HTML, I have an array of inputs. The user should be allowed to enter only one character in each. Here is its HTML:
<input class = "green" type="text" maxlength="1" />
The CSS for this is as follows:
input {
font: 1.5em "Times New Roman", Times, serif;
width:0.9em; height: 0.9em;
text-align:center; }
.green {
color: green; }
If the user enters a character and then tries to enter another, nothing should happen. However, in my design the user can enter any number of characters, even though the earlier characters are pushed to the left and only the last character is visible. When the focus leaves the input field, all extra characters disappear and only the first input character remain. How can I make sure that when the user tries to enter additional characters, they are ignored and nothing happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是您需要的吗?
Is it what you need?