$(document).on("input propertychange","#recognisAmount",function(){ // this.value=this.value.replace(/\s+/g,'') // this.value=(this.value.match(/\d{0,8}/)); this.value=(this.value.match(/\d{1,8}(\.\d{0,2})?/)||[''])[0]; })
实例1.<html>
<head>
<meta charset="utf-8" />
<title>jQuery文本框过滤空格</title>
<script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<div>禁止输入空格:<input type="text" id="test"/></div>
<div>只能输入数字:<input type="text" id="tests"/></div>
<script>
//禁止输入空格
$(document).on("input propertychange","#test",function(){
this.value=this.value.replace(/\s+/g,'')
})
//只能输入数字前8后2
$(document).on("input propertychange","#tests",function(){
this.value=(this.value.match(/\d{1,8}(\.\d{0,2})?/)||[''])[0];
});
</script>
</body>
</html>