<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>input type=number 禁止输入小数点</title>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<script src="jquery.min.js" type="text/javascript"></script>
</head>
<body>
<input type="text" name="number" id='number'/>
<script>
//1
$(document).ready(function(){
var ipt = $('#number');
ipt.on('keyup',function(){
if(! /^\d+$/.test(this.value)){
this.value='';
}
})
});
//2
if(!/^[-]?[0-9]*\.?[0-9]+(eE?[0-9]+)?$/.test(ele.value)){ //校验数子
return false;
}
if(ele.value.indexOf('.') !=-1){ //校验.
return false;
}
</script>
</body>
</html>
input 输入框禁止输入小数点
最新推荐文章于 2024-09-12 17:27:43 发布