用JS(JavaScript)判断一个控件的输入值是不是整数,非正则表达式版本

  window.checkForm = function () {
            var initNum = $.trim($("input[id$=txtInitNum]").val());
            var strAlert = "请输入正确的数字!";
            if (initNum != "") {
                try {
                    if (isNaN(parseInt(initNum))) {

                        window.alert(strAlert);
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                catch (ex) {
                    window.alert(strAlert);
                    return false;
                }
            }
            else {
                window.alert(strAlert);
                return false;
            }

你可能感兴趣的:(JavaScript,js)