Jul*_*les 33 safari html5 maxlength
我喜欢输入最多3个字符.在Firefox中一切正常我只能在输入中写入3个数字 - 但在safari中你可以在里面写很多数字.
你可以在这两个浏览器中测试它:http://flowplayer.org/tools/demos/validator/custom-validators.htm
现在我用验证插件意识到它 - 但只是为了兴趣我想知道为什么这不起作用?
编辑:
有了这个它的工作
<input class="required" id="field" type="text" maxlength="3" pattern="([0-9]|[0-9]|[0-9])" name="cvv"/>
Run Code Online (Sandbox Code Playgroud)
Jul*_*les 31
我完成了它:
<input class="required" id="field" type="text" maxlength="3" pattern="([0-9]|[0-9]|[0-9])" name="cvv"/>
Run Code Online (Sandbox Code Playgroud)
然后在JavaScript中我阻止了这些字母:
$("#myField").keyup(function() {
$("#myField").val(this.value.match(/[0-9]*/));
});
Run Code Online (Sandbox Code Playgroud)
小智 14
您可以尝试使用type ="text"和oninput,如下所示.这只会是数字.
<input type="text" maxlength="3" oninput="this.value=this.value.replace(/[^0-9]/g,'');" id="myId"/>
Run Code Online (Sandbox Code Playgroud)
使用onKeyDown可以限制长度
<input type="number" onKeyDown="if(this.value.length==10 && event.keyCode!=8) return false;">
Run Code Online (Sandbox Code Playgroud)
快乐编码:)
基本上Safari 浏览器还不支持Max和Min属性。我看不出语法上有什么缺陷。您使用的是 Safari 1.3+ 版本吗?或者低于那个?因为maxlength属性从 safari 1.3+ 开始支持。
归档时间: |
|
查看次数: |
95973 次 |
最近记录: |