//检查输入 var tip_top =50; //获取tip function getValDiv(exId) { var divObj; divObj = document.createElement("div"); divObj.id = "val_div_" + exId; divObj.className = "val_div"; return divObj; } function getAbsolutePosition(element) { var point = { x: element.offsetLeft, y: element.offsetTop }; if (element.offsetParent) { var parentPoint = this.getAbsolutePosition(element.offsetParent); point.x += parentPoint.x; point.y += parentPoint.y; } return point; }; //加载Tip function addTip(inputObj) { var inputWidth = parseInt($(inputObj).width()); var exId = inputObj.id; var divObj = document.getElementById("val_div_" + exId); if (!divObj) { var point = getAbsolutePosition(inputObj); divObj = getValDiv(exId); divObj.style.top = (point.y - 52 +(tip_top)) + "px"; divObj.style.left = (point.x + 140 + 20) + "px"; /* divObj.style.top =(point.y+30) + "px"; divObj.style.left = point.x + "px"; */ var pObj = inputObj.parentNode; if (pObj.nodeName != "TD") pObj = pObj.parentNode; pObj.appendChild(divObj); } } //获取列 function getCellIndex(o) { var obj = o.parentNode.cells; for (var i = 0; i < obj.length; i++) { if (o == obj[i]) return i; } } //显示错误 function tipShowError(exId, errMsg) { if (errMsg) { $("#val_div_" + exId).empty(); var str = "
"; str += ""; str += errMsg + "
"; $("#val_div_" + exId).append($(str)); $("#" + exId).bind({ focus: function () { if ($("#val_div_" + exId).length > 0) $("#val_div_" + exId).empty(); } }); } } //显示正确 function tipShowOk(exId) { //$("#" + exId).attr("class", "webtext"); var str = ""; $("#val_div_" + exId).append($(str)); $("#" + exId).bind({ focus: function () { if ($("#val_div_" + exId).length > 0) $("#val_div_" + exId).empty(); } }); } //计算字符数,一个中文2个字符 function fLen(obj) { var nCNLenth = 0; var nLenth = obj.length; for (var i = 0; i < nLenth; i++) { if (obj.charCodeAt(i) > 255) { nCNLenth += 2; } else { nCNLenth++; } } return nCNLenth; } //运行函数 function runFunction(sFunc) { eval(sFunc + "()"); } //获取结果显示 function getCheckMsg(sId, eMsg) { if (eMsg.length > 0) { tipShowError(sId, eMsg); return false; } else { tipShowOk(sId); return true; } } function checkInput(sId, msg, reg) { addTip($("#" + sId)[0]); var errMsg = ""; var v = $("#" + sId).val(); if (v == "") errMsg = msg + "不允许为空!"; if (v == $("#" + sId).attr('def')) errMsg = msg + "不允许为空!"; else if (reg && !new RegExp(reg).test(v)) { errMsg = msg + "不符合规范!"; } return getCheckMsg(sId, errMsg); } function checkDefInput(sId, msg) { addTip($("#" + sId)[0]); var errMsg = ""; if ($("#" + sId).val() == "" || $("#" + sId).val() == $("#" + sId).attr("def")) { errMsg = msg + "不允许为空!"; $("#" + sId).val(""); } return getCheckMsg(sId, errMsg); } //检查数字输入 function checkNumInput(sId, msg, min) { addTip($("#" + sId)[0]); var errMsg = ""; var v = $("#" + sId).val(); if (v == "") errMsg = msg + "不允许为空!"; else if (parseInt(v) < min) errMsg = msg + "不允许小于" + min; return getCheckMsg(sId, errMsg); } //检查日期 function checkDateInput(sId, eId, msg) { addTip($("#" + sId)[0]); var errMsg = ""; if ($("#" + sId).val() == "") return getCheckMsg(sId, msg + "不允许为空!"); else if ($("#" + eId).val() == "") return getCheckMsg(eId, msg + "不允许为空!"); return true; } function toWeight(money) { if (money == "") return 0; return Math.round(parseFloat(money) * 1000) / 1000; } function validCombobox(e) { var items = this.findItems(e.value); if (!items || items.length == 0) { e.sender.setValue(""); } } $(document).ready(function () { if (/msie [1-7].0/.test(navigator.userAgent.toLowerCase()) && $("html")[0].scrollHeight > $("html").height()) { $("html").css("overflowY", "scroll"); } }); //对象,小数点,允许负数 function allowNumber(obj, decimals, min, max, allowMinus) { var v = obj.value; if (!min) min = 0; //if (v == "") { obj.value = min; return; } if (!max) max = 10000; //默认不允许小数 if (!allowMinus) allowMinus = false; //如果没有指定小数,则不允许小数 if (!decimals) decimals = 0; var res = ""; for (i = 0; i < v.length; i++) { if (i == 0 && v.charAt(0) == "-" && allowMinus == true) res = "-"; else { //判断是否是数字 if (/\d/.test(v.charAt(i))) res += v.charAt(i); else { if (v.charAt(i) == "." && decimals > 0) { res += v.charAt(i); } } } } if (res.length > 0) { //不允许0开头后面还有0 if (res.substring(0, 1) == "0" && res.length > 1 && res.substring(0, 2) != "0.") { res = res.substring(1); } //负数不允许0开头后面还有0 if (res.substring(0, 2) == "-0" && res.length > 2 && res.substring(0, 3) != "-0.") { res = res.substring(0, 2); } //有小数点 if (res.indexOf(".") != -1) { //第一个字符不允许是小数点 if (res.substring(0, 1) == ".") { res = res.replace(".", ""); } else { //只允许有一个小数点 if (res.indexOf(".") != res.lastIndexOf(".")) { res = res.substring(0, res.indexOf(".") + 1) + res.substring(res.indexOf(".") + 1).replace(".", ""); } //不允许超出小数位 if (res.substring(res.indexOf(".") + 1).length > decimals) { res = res.substring(0, res.indexOf(".") + decimals + 1); } } } if (parseFloat(res) < min) res = min; if (max > 0) { if (parseFloat(res) > max) res = max; } } obj.value = res; } //纠正数字 function correctNumber(obj) { var v = obj.value; //删除只有一个负数符号的情况 if (v == "-") v = ""; //删除最后一个是小数点的情况 var dIdx = v.indexOf("."); if (v.length == dIdx + 1) v = v.substring(0, dIdx); //if (v == "") v = 0; obj.value = v; } function upNumber(dObj, max) { var tr = dObj.parentNode.parentNode; var obj = tr.getElementsByTagName("input")[0]; var sv = obj.value != "" ? parseFloat(obj.value) : 0; if (sv + 1 <= max) { obj.value = sv + 1; } } function downNumber(dObj, min) { var tr = dObj.parentNode.parentNode; var obj = tr.getElementsByTagName("input")[0]; var sv = obj.value != "" ? obj.value : 0; if (sv - 1 >= min) { obj.value = sv - 1; } } function closeFn(flag) { if (window.CloseOwnerWindow) { if (flag != undefined) window.CloseOwnerWindow("save"); else window.CloseOwnerWindow("close"); } else { window.close(); } } $(document).keydown(function (e) { if (e.which == 8) { var targ = null; if (e.target) targ = e.target; else targ = e.srcElement; if ((targ.type == "textarea" && (targ.getAttribute("readonly") == null || targ.getAttribute("readonly") == "")) || targ.type == "text") return true; else return false; } else if (e.which == 13) { hideKB(); closeKB(); } }); function closeKB() { }