html - 限制表单输入文本字段中允许的字符数

标签 html forms input textbox

如何限制或限制用户在文本框中最多只能输入五个字符?

下面是作为我表单一部分的输入字段:

<input type="text" id="sessionNo" name="sessionNum" />

它是否使用类似 maxSize 之类的东西?

最佳答案

maxlength :

The maximum number of characters that will be accepted as input. This can be greater that specified by SIZE , in which case the field will scroll appropriately. The default is unlimited.

<input type="text" maxlength="2" id="sessionNo" name="sessionNum" onkeypress="return isNumberKey(event)" />

但是,这可能会或可能不会受到您的处理程序的影响。您可能还需要使用或添加另一个处理函数来测试长度。

关于html - 限制表单输入文本字段中允许的字符数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8545376/

相关文章:

javascript - 输入值有时不适用

c - 将输入文件名保存为字符串? C

html - Century Gothic字体效果图

forms - 如何允许用户在不登录的情况下使用 Google Form 上传文件?

PHP从表单传递和接收二维数组

javascript - 使用 Javascript 添加的 HTML 表单隐藏字段未发布

Java - 将用户输入放入数组中

javascript - Bootstrap Modal 引用输入字段值(不起作用)

jquery - 下拉导航的最佳方法

javascript - 向 onclick 属性添加函数奇怪的行为