我想控制输入框只能输入四个字符的数字,如 12.5 12
如果有小数就必须是 .5 只可以是一位小数,最大数不要超过31
请问正侧限制怎么写?
<input size="2" name="Report_date" maxlength="4" onkeyup="代码?">
如果有小数就必须是 .5 只可以是一位小数,最大数不要超过31
请问正侧限制怎么写?
<input size="2" name="Report_date" maxlength="4" onkeyup="代码?">
调试欢乐多
就是输入0.5会出错
我的值是用于考勤时间的,所以不能大于31,可以等于31
最小值是0.5
其他就是如1.5 12 22.5 22 10 之类的,以0.5为倍数!
<input type='text' size="4" name="Report_date" id="Report_date" maxlength="4" onblur="ck(this.id)" onkeyup="this.value=this.value.replace(/[^\d.]/g,'');if(this.value=='.')this.value='0.';">
<script>
function $(id){
if(!document.getElementById(id)){
alert("ID:"+id+" 对象不存在!");return false;
}else{return document.getElementById(id);}
}
function ck(id){
var v=$(id).value;
if(v%0.5!=0||v<0||v>31||v==""){
alert("请输入0.5倍数的数!");
$(id).value=0;
}
}
</script>