<input type="number" maxlength="5" class="search-form-input" name="techforge_apartmentbundle_searchformtype[radius]" id="techforge_apartmentbundle_searchformtype_radius">
这是我的HTML,用firebug拍摄的(在chrome上)。
在Chrome和Safari中,我可以在表单字段中输入任意数量的字符。
在火狐或IE10上,这个限制是可以接受的。
我还没有在网上找到这个问题。
注意:type=“数字”--不是文本。
以前有没有人见过这个问题?
发布于 2012-03-04 21:22:14
发布于 2016-06-16 00:57:58
最大长度不适用于<input type="number"
,据我所知,最好的方法是使用oninput event来限制最大长度。请看下面的代码。
<input name="somename"
oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
type = "number"
maxlength = "6"
/>
发布于 2013-03-07 17:16:45
对于那些仍然不能让它工作的人...试试这个来启动更大的数字垫:
<input type="number" name="no1" maxlength="1" size="1" max="9" pattern="[0-9]*" />
和js:
$('input[name="no1"]').keypress(function() {
if (this.value.length >= 1) {
return false;
}
});
https://stackoverflow.com/questions/9555143
复制相似问题