HTML maxlength属性不适用于Chrome和Safari浏览器? [英] HTML maxlength attribute not working on chrome and safari?

查看:293
本文介绍了HTML maxlength属性不适用于Chrome和Safari浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < input type =numbermaxlength =5class =search-form-inputname =techforge_apartmentbundle_searchformtype [radius]id =techforge_apartmentbundle_searchformtype_radius> 

这是我的HTML,使用萤火虫(在chrome上)。



允许我在表单字段中编写与字符一样多的字符 - 在Chrome和Safari中。



在Firefox或IE10上,这个限制没有问题。



我没有在网上发现这个问题。



注意:type =数字 - 不是文本。



任何人在看过这个问题之前?

解决方案

使用max属性输入 type =number。它会指定您可能插入的最大数字。

 < input type =numbermax =999/> ; 

如果同时添加最大值和最小值,则可以指定允许值的范围:

 < input type =numbermin =1max =999/> 

请参阅此示例
$ b 编辑



如果对于用户体验,您更希望用户不能够输入超过一定的数字,使用Javascript / jQuery,如此示例所示


<input type="number" maxlength="5" class="search-form-input" name="techforge_apartmentbundle_searchformtype[radius]" id="techforge_apartmentbundle_searchformtype_radius">

This is my HTML, taken with firebug (on chrome).

I am allowed to write as much as characters as I want in the form field - in Chrome and Safari.

When on Firefox or IE10, the limit is fine.

I haven't found this issue around on the net.

Note: type="number" - not text.

Anyone saw this issue before?

解决方案

Use the max attribute for inputs of type="number". It will specify the highest possible number that you may insert

  <input type="number" max="999" />

if you add both a max and a min value you can specify the range of allowed values:

  <input type="number" min="1" max="999" />

See this example

EDIT

If, for user experience, you would prefer the user not to be able to enter more than a certain number, use Javascript/jQuery, as seen in this example

这篇关于HTML maxlength属性不适用于Chrome和Safari浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆