这工作正常,但如果我使用我的数字键盘(右侧),它会认为它是一个字符并删除它,但左侧的数字被接受。我希望我的数字键盘(右侧)被接受。
<script type="text/javascript">
$("input[name='inputDate']:first").keyup(function(e){
var key=String.fromCharCode(e.keyCode);
if(!( key >= 0 && key <= 9 )) {
$(this).val($(this).val().substr(0,$(this).val().length-1));
}
});
</script>
更新了这个(已经解决)
<script type="text/javascript">
$("input[name='birthdate']:first").on('keyup', function(e){
var val = $(this).val();
var key = val.substr(val.length - 1)
var value=$(this).val();
if(value.length === 2|| value.length === 5)$(this).val($(this).val()+'/');
if(!(key>=0&&key<=9))
$(this).val(val.substr(0,val.length-1));
});
</script>