请写出用于校验HTML文本框中输入的内容全部为数字的javascript代码

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script type="text/javascript">
        function chkNumber(eleText) {
            var value = eleText.value;
            var len = value.length;
            for(var i = 0;i < len;i++) {
                if(value.charAt(i) > "9" || value.charAt(i) < "0") {
                    alert("含有非数字字符");
                    eleText.focus();
                    break;
                }
            }
        }
    </script>
</head>
<body>
<input type="text" id="d1" onblur="chkNumber(this)"/>
</body>
</html>

 

posted on 2017-10-27 17:56    阅读(1194)  评论(0编辑  收藏  举报