- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript">
-
-
-
-
- function checkKeyForFloat(value, e) {
- var isOK = false;
- var key = window.event ? e.keyCode : e.which;
- if ((key > 95 && key < 106) ||
- (key > 47 && key < 60) ||
- (key == 110 && value.indexOf(".") < 0) ||
- (key == 190 && value.indexOf(".") < 0) ||
- key == 8 || key == 9 || key == 46 || key == 37 || key == 39
- ) {
- isOK = true;
- } else {
- if (window.event)
- {
- e.returnValue = false;
- }
- else
- {
- e.preventDefault();
- }
- }
- return isOK;
- }
-
-
- function checkKeyForInt(value, e) {
- var isOK = false;
- var key = window.event ? e.keyCode : e.which;
- if ((key > 95 && key < 106) ||
- (key > 47 && key < 60) ||
- key == 8 || key == 9 || key == 46 || key == 37 || key == 39
- ) {
- isOK = true;
- } else {
- if (window.event)
- {
- e.returnValue = false;
- }
- else
- {
- e.preventDefault();
- }
- }
- return isOK;
- }
-
-
- function setDType() {
- $(":text[dtype]").each(function () {
- var dtype = $(this).attr("dtype");
- var isOK = true;
- switch (dtype) {
- case "number":
- $(this).css("ime-mode", "disabled").keydown(function (event) {
- isOK = checkKeyForFloat($(this).val(), event);
- if (!isOK) {
-
- }
- return isOK;
- });
- break;
- default:
- break;
- }
- });
- }
- </script>
- <script type="text/javascript">
- $(function () {
- setDType();
- });
- </script>
- </head>
- <body>
- 年龄: <input type="text" maxlength="3" onkeydown="checkKeyForInt(this.value,event)" style="ime-mode: disabled"/><br />
- 身高:<input type="text" maxlength="5" dtype="number" />
- </body>
- </html>
posted @
2013-08-14 10:30
namehwh
阅读(
711)
评论()
编辑
收藏
举报