/*判断当前对象是否可见*/
- function isVisible(obj){
- var visAtt,disAtt;
- try{
- disAtt=obj.style.display;
- visAtt=obj.style.visibility;
- }catch(e){}
- if(disAtt=="none" || visAtt=="hidden")
- return false;
- return true;
- }
-
function isVisible(obj){
var visAtt,disAtt;
try{
disAtt=obj.style.display;
visAtt=obj.style.visibility;
}catch(e){}
if(disAtt=="none" || visAtt=="hidden")
return false;
return true;
}
/*判断当前对象及其父对象是否可见*/
- function checkPrVis(obj){
- var pr=obj.parentNode;
- do{
- if(pr == undefined || pr == "undefined") return true;
- else{
- if(!isVisible(pr)) return false;
- }
- }while(pr=pr.parentNode);
- return true;
- }
-
function checkPrVis(obj){
var pr=obj.parentNode;
do{
if(pr == undefined || pr == "undefined") return true;
else{
if(!isVisible(pr)) return false;
}
}while(pr=pr.parentNode);
return true;
}
/* 弹出警告对话框,用户点确定后将光标置于出错文本框上, 并且将原来输入内容选中。*/
- function f_alert(obj,alertInfo)
- {
- var caption = obj.getAttribute("eos_displayname");
- if(caption == null)
- caption = "";
- alert(caption + ":" + alertInfo + "!");
- obj.select();
- if(isVisible(obj) && checkPrVis(obj))
- obj.focus();
- }
-
function f_alert(obj,alertInfo)
{
var caption = obj.getAttribute("eos_displayname");
if(caption == null)
caption = "";
alert(caption + ":" + alertInfo + "!");
obj.select();
if(isVisible(obj) && checkPrVis(obj))
obj.focus();
}
/**
* 检测字符串是否为空
*/
- function isnull(str)
- {
- var i;
- if(str.length == 0)
- return true;
- for (i=0;i<str.length;i++)
- {
- if (str.charAt(i)!=' ')
- return false;
- }
- return true;
- }
-
function isnull(str)
{
var i;
if(str.length == 0)
return true;
for (i=0;i<str.length;i++)
{
if (str.charAt(i)!=' ')
return false;
}
return true;
}
/**
* 检测指定文本框输入是否合法。
* 如果用户输入的内容有错,则弹出提示对话框,
* 同时将焦点置于该文本框上,并且该文本框前面
* 会出现一个警告图标(输入正确后会自动去掉)。
*/
- function checkInput(object)
- {
- var image;
- var i;
- var length;
-
- if(object.eos_maxsize + "" != "undefined") length = object.eos_maxsize;
- else length = 0;
-
- if (object.eos_isnull=="true" && isnull(object.value)) return true;
-
-
- if(length != 0 && strlen(object.value) > parseInt(length)) {
- f_alert(object, "超出最大长度" + length);
- return false;
- }
-
- else {
- if (object.eos_datatype + "" != "undefined")
- {
-
- var dtype = object.eos_datatype;
- var objName = object.name;
-
- if(dtype.indexOf("(") != -1)
- dtype = dtype.substring(0,dtype.indexOf("("));
-
- try{
- if(eval("f_check_" + dtype + "(object)") != true)
- return false;
- }catch(e){return true;}
-
-
- if(objName.substring((objName.length-3),objName.length)=="min")
- {
- var objMaxName = objName.substring(0, (objName.length-3)) + "max";
- if(document.getElementById(objMaxName) != undefined && document.getElementById(objMaxName) != "undefined" )
- {
- if(checkIntervalObjs(object, document.getElementById(objMaxName)) != true)
- return false;
- }
- }
- }
- }
- return true;
- }
-
function checkInput(object)
{
var image;
var i;
var length;
if(object.eos_maxsize + "" != "undefined") length = object.eos_maxsize;
else length = 0;
if (object.eos_isnull=="true" && isnull(object.value)) return true;
/* 长度校验 */
if(length != 0 && strlen(object.value) > parseInt(length)) {
f_alert(object, "超出最大长度" + length);
return false;
}
/* 数据类型校验 */
else {
if (object.eos_datatype + "" != "undefined")
{
var dtype = object.eos_datatype;
var objName = object.name;
//如果类型名后面带有括号,则视括号前面的字符串为校验类型
if(dtype.indexOf("(") != -1)
dtype = dtype.substring(0,dtype.indexOf("("));
//根据页面元素的校验类型进行校验
try{
if(eval("f_check_" + dtype + "(object)") != true)
return false;
}catch(e){return true;}
/* 如果form中存在name前半部分相同,并且同时存在以"min"和"max"结尾的表单域,
那么视为按区间查询。即"min"结尾的表单域的值要小于等于"max"结尾的表单域的值。 */
if(objName.substring((objName.length-3),objName.length)=="min")
{
var objMaxName = objName.substring(0, (objName.length-3)) + "max";
if(document.getElementById(objMaxName) != undefined && document.getElementById(objMaxName) != "undefined" )
{
if(checkIntervalObjs(object, document.getElementById(objMaxName)) != true)
return false;
}
}
}
}
return true;
}
/* 检测表单中所有输入项的正确性,一般用于表单的onsubmit事件 */
- function checkForm(myform)
- {
- var i;
- for (i=0;i<myform.elements.length;i++)
- {
-
- if (myform.elements[i].eos_displayname + "" == "undefined") continue;
-
- if (myform.elements[i].eos_isnull=="false" && isnull(myform.elements[i].value)){
- f_alert(myform.elements[i],"不能为空");
- return false;
- }
-
- if (checkInput(myform.elements[i])==false)
- return false;
- }
- return true;
- }
-
function checkForm(myform)
{
var i;
for (i=0;i<myform.elements.length;i++)
{
/* 非自定义属性的元素不予理睬 */
if (myform.elements[i].eos_displayname + "" == "undefined") continue;
/* 非空校验 */
if (myform.elements[i].eos_isnull=="false" && isnull(myform.elements[i].value)){
f_alert(myform.elements[i],"不能为空");
return false;
}
/* 数据类型校验 */
if (checkInput(myform.elements[i])==false)
return false;
}
return true;
}
/**
* 校验两个表单域数据的大小,目前只允许比较日期和数字。
* @param obj1 小值表单域
* @param obj2 大值表单域
*/
- function checkIntervalObjs(obj1 , obj2)
- {
- var caption1 = obj1.getAttribute("eos_displayname");
- var caption2 = obj2.getAttribute("eos_displayname");
- var val1 = parseFloat(obj1.value);
- var val2 = parseFloat(obj2.value);
-
- if (obj1.eos_displayname + "" == "undefined" || obj2.eos_displayname + "" == "undefined") {
- return false;
- }
-
- if(f_check_date(obj1) == true && f_check_date(obj2) == true){
- var dtype = obj1.eos_datatype;
- var format = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")"));
- val1 = getDateByFormat(obj1.value, format);
- dtype = obj2.eos_datatype;
- format = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")"));
- val2 = getDateByFormat(obj2.value, format);
- if(val1 > val2){
- obj2.select();
- if(isVisible(obj) && checkPrVis(obj))
- obj2.focus();
- alert(caption1 + "的起始日期不能大于其终止日期!");
- return false;
- }
- }
-
- if((isNaN(val1) && !isnull(val1)) || (isNaN(val2) && !isnull(val2))){
- alert(caption1 + "的值不全为数字则不能比较!");
- return false;
- }
- if(val1 > val2){
- obj2.select();
- if(isVisible(obj) && checkPrVis(obj))
- obj2.focus();
- alert(caption1 + "的起始值不能大于其终止值!");
- return false;
- }
- return true;
- }
-
function checkIntervalObjs(obj1 , obj2)
{
var caption1 = obj1.getAttribute("eos_displayname");
var caption2 = obj2.getAttribute("eos_displayname");
var val1 = parseFloat(obj1.value);
var val2 = parseFloat(obj2.value);
// 非自定义属性的元素不予理睬
if (obj1.eos_displayname + "" == "undefined" || obj2.eos_displayname + "" == "undefined") {
return false;
}
// 日期类型的比较
if(f_check_date(obj1) == true && f_check_date(obj2) == true){
var dtype = obj1.eos_datatype;
var format = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")); //日期格式
val1 = getDateByFormat(obj1.value, format);
dtype = obj2.eos_datatype;
format = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")); //日期格式
val2 = getDateByFormat(obj2.value, format);
if(val1 > val2){
obj2.select();
if(isVisible(obj) && checkPrVis(obj))
obj2.focus();
alert(caption1 + "的起始日期不能大于其终止日期!");
return false;
}
}
// 数字类型的比较
if((isNaN(val1) && !isnull(val1)) || (isNaN(val2) && !isnull(val2))){
alert(caption1 + "的值不全为数字则不能比较!");
return false;
}
if(val1 > val2){
obj2.select();
if(isVisible(obj) && checkPrVis(obj))
obj2.focus();
alert(caption1 + "的起始值不能大于其终止值!");
return false;
}
return true;
}
/*根据日期格式,将字符串转换成Date对象。
格式:yyyy-年,MM-月,dd-日,HH-时,mm-分,ss-秒。
(格式必须写全,例如:yy-M-d,是不允许的,否则返回null;格式与实际数据不符也返回null。)
默认格式:yyyy-MM-dd HH:mm:ss,yyyy-MM-dd。*/
- function getDateByFormat(str){
- var dateReg,format;
- var y,M,d,H,m,s,yi,Mi,di,Hi,mi,si;
- if((arguments[1] + "") == "undefined") format = "yyyy-MM-dd HH:mm:ss";
- else format = arguments[1];
- yi = format.indexOf("yyyy");
- Mi = format.indexOf("MM");
- di = format.indexOf("dd");
- Hi = format.indexOf("HH");
- mi = format.indexOf("mm");
- si = format.indexOf("ss");
- if(yi == -1 || Mi == -1 || di == -1) return null;
- else{
- y = parseInt(str.substring(yi, yi+4));
- M = parseInt(str.substring(Mi, Mi+2));
- d = parseInt(str.substring(di, di+2));
- }
- if(isNaN(y) || isNaN(M) || isNaN(d)) return null;
- if(Hi == -1 || mi == -1 || si == -1) return new Date(y, M-1, d);
- else{
- H = str.substring(Hi, Hi+4);
- m = str.substring(mi, mi+2);
- s = str.substring(si, si+2);
- }
- if(isNaN(parseInt(y)) || isNaN(parseInt(M)) || isNaN(parseInt(d))) return new Date(y, M-1, d);
- else return new Date(y, M-1, d,H, m, s);
- }
-
function getDateByFormat(str){
var dateReg,format;
var y,M,d,H,m,s,yi,Mi,di,Hi,mi,si;
if((arguments[1] + "") == "undefined") format = "yyyy-MM-dd HH:mm:ss";
else format = arguments[1];
yi = format.indexOf("yyyy");
Mi = format.indexOf("MM");
di = format.indexOf("dd");
Hi = format.indexOf("HH");
mi = format.indexOf("mm");
si = format.indexOf("ss");
if(yi == -1 || Mi == -1 || di == -1) return null;
else{
y = parseInt(str.substring(yi, yi+4));
M = parseInt(str.substring(Mi, Mi+2));
d = parseInt(str.substring(di, di+2));
}
if(isNaN(y) || isNaN(M) || isNaN(d)) return null;
if(Hi == -1 || mi == -1 || si == -1) return new Date(y, M-1, d);
else{
H = str.substring(Hi, Hi+4);
m = str.substring(mi, mi+2);
s = str.substring(si, si+2);
}
if(isNaN(parseInt(y)) || isNaN(parseInt(M)) || isNaN(parseInt(d))) return new Date(y, M-1, d);
else return new Date(y, M-1, d,H, m, s);
}
/*LTrim(string):去除左边的空格*/
- function LTrim(str){
- var whitespace = new String(" \t\n\r");
- var s = new String(str);
-
- if (whitespace.indexOf(s.charAt(0)) != -1){
- var j=0, i = s.length;
- while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
- j++;
- }
- s = s.substring(j, i);
- }
- return s;
- }
-
function LTrim(str){
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(0)) != -1){
var j=0, i = s.length;
while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
j++;
}
s = s.substring(j, i);
}
return s;
}
/*RTrim(string):去除右边的空格*/
- function RTrim(str){
- var whitespace = new String(" \t\n\r");
- var s = new String(str);
-
- if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
- var i = s.length - 1;
- while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
- i--;
- }
- s = s.substring(0, i+1);
- }
- return s;
- }
-
function RTrim(str){
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
var i = s.length - 1;
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
i--;
}
s = s.substring(0, i+1);
}
return s;
}
/*Trim(string):去除字符串两边的空格*/
- function Trim(str){
- return RTrim(LTrim(str));
- }