见代码:
<html>
<script src="jquery.js"></script>
<script>
var rules = {};
function keyPress(e) {
var decimal = /^\d{1,4}(\.\d{0,1})?$/;
var value = $(this).val();
var property = $(this).attr("id");
if(value == "" || decimal.test(value)){
rules[property] = value;
return;
}
if(rules.hasOwnProperty(property)){
$(this).val(rules[property]);
}else{
$(this).val("");
}
}
$(function(){
$("input[type=text]").bind("input",keyPress);
$("input[type=text]").bind("propertychange",keyPress);
});
</script>
<input type="text" id="inputa"/>
</html>