为什么< input type =“number” MAXLENGTH = QUOT; 3英寸;>不在Safari上工作? [英] why is <input type="number" maxlength="3"> not working in Safari?
问题描述
我喜欢输入最多3个字符。在Firefox中一切正常,我只能在输入内写入3个数字 - 但在safari中,您可以在内部写入大量数字。
您可以在两种浏览器中测试这: http://flowplayer.org/tools/demos/validator/custom- validators.htm
现在我用一个验证插件意识到它 - 但仅仅为了兴趣,我想知道为什么它不起作用?
编辑:
用此工作
< input class =requiredid =fieldtype =textmaxlength =3pattern =([0-9] | [0- 9] | [0-9])name =cvv/>
< input class =requiredid =field type =textmaxlength =3pattern =([0-9] | [0-9] | [0-9])name =cvv/>
然后在JavaScript中,我阻止了这些字母:
$(#myField)。keyup(function(){
$(#myField).val(this.value.match(/ [0- 9] * /));
});
I like to have an input with maximum 3 characters. In Firefox everything works fine I can only write 3 numbers inside the input - but in safari you can write a lot of numbers inside.
You can test it in both browsers with this: http://flowplayer.org/tools/demos/validator/custom-validators.htm
For now I realized it with a validate plugin - but just for interest I like to know why isn’t this working?
EDIT:
with this it's working
<input class="required" id="field" type="text" maxlength="3" pattern="([0-9]|[0-9]|[0-9])" name="cvv"/>
answer: How can I prevent letters inside a text element?
I've accomplished it with:
<input class="required" id="field" type="text" maxlength="3" pattern="([0-9]|[0-9]|[0-9])" name="cvv"/>
and then in JavaScript I prevented the letters:
$("#myField").keyup(function() {
$("#myField").val(this.value.match(/[0-9]*/));
});
这篇关于为什么< input type =“number” MAXLENGTH = QUOT; 3英寸;>不在Safari上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!