我一直在使用这个 $("#SomeId").mask("99"); 我只想输入两位数字的文本框的 jquery 掩码,但我不知道要输入哪个掩码才能仅输入一位数字和两位数字。从 0-99
上面的掩码我无法输入一位数字,文本框失去焦点时变为空白。
我一直在使用这个 $("#SomeId").mask("99"); 我只想输入两位数字的文本框的 jquery 掩码,但我不知道要输入哪个掩码才能仅输入一位数字和两位数字。从 0-99
上面的掩码我无法输入一位数字,文本框失去焦点时变为空白。
{mask: 9, 'maxLength': 2} 应该可以
编辑:你还没有指定你使用了什么面具;我的回答与meioMask插件有关。
编辑 2:对于 maskedinput 1.2.2:
$("#SomeId").mask("9?9");
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#test').keypress(allowOnlyTwoPositiveDigts);
});
function allowOnlyTwoPositiveDigts(e){
var test = /^[\-]?[0-9]{1,2}?$/
return test.test(this.value+String.fromCharCode(e.which))
}
</script>
</head>
<body>
<input id="test" type="text" />
</body>
</html>
<input id="id_input" class=".class_input" type="text" />
$('#id_input').mask('99');
$('.class_input').mask('99');