<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>只能输入数字</title>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function(){
$('input[type=text]').keypress(function(e) {
if (!String.fromCharCode(e.keyCode).match(/[0-9\.]/)) {
return false;
}
});
});
</script>
</head>
<body>
<input type="text" style="width: 190px;">
</body>
</html>