var curCtlIndex = 0;
var arrCtl = new Array();
var oldEvent = new Array();
//設置焦點控件?
function SetFocusToFirstControl()
{
var i = 0,j = -1;
for(i=0;i<document.forms[0].elements.length;i++)
{
if(document.forms[0].elements[i].tagName == 'INPUT' || document.forms[0].elements[i].tagName == 'SELECT' || document.forms[0].elements[i].tagName == 'TEXTAREA')
{
if(document.forms[0].elements[i].type != 'submit' && document.forms[0].elements[i].type != 'reset' && document.forms[0].elements[i].type != 'hidden' && document.forms[0].elements[i].type != 'button')
{
if(document.forms[0].elements[i].disabled == 'disabled' || document.forms[0].elements[i].disabled == true)?
continue;
if(document.forms[0].elements[i].readOnly)?
continue;
if(document.forms[0].elements[i].style.display =="none")?
continue;
if(document.forms[0].elements[i].style.width == "0px")
continue;
try
{
j++;
arrCtl[j] = document.forms[0].elements[i];
arrCtl[j].blur();
}
catch(el)
{ }
}
document.forms[0].elements[i].onblur = onblur_handler;
document.forms[0].elements[i].onfocus = onfocus_handler;
}
//alert(document.forms[0].elements[i].type + document.forms[0].elements[i].tagName);
}
//alert(arrCtl.length);
for(i=0;i<arrCtl.length;i++)
{
try
{
arrCtl[i].focus();
break;
}
catch(el)
{}
}
}
/*
設置 回車鍵
*/
function keyEnter(objSubmit)?
{
var i = 0;
if(event.keyCode == 13) ?// || event.keyCode == 39 || event.keyCode == 40
{
for(i=curCtlIndex+1;i<arrCtl.length;i++)
{
if(curCtlIndex < arrCtl.length - 1)
{
try
{
curCtlIndex++;
arrCtl[curCtlIndex].focus();
? ? ? ? ? ?return false;
//break;
}
catch(el)
{}
}
else
{
//break;
}
} ??
if(objSubmit != undefined && objSubmit != '' )
? ?document.getElementById(objSubmit).click();
return false;
}
else if(event.keyCode == 37) ? ?// || event.keyCode == 38
{
for(i=curCtlIndex-1;i>=0;i--)
{
try
{
curCtlIndex--;
arrCtl[curCtlIndex].focus();
break;
}
catch(el)
{}
}
return false;
}
}
/*****************************************************************
返回數字,不包含小數點
****************************************************************/
function returnNumber()
{
?? ?//alert('21332');
?? ?return (event.keyCode>47 && event.keyCode<58);
}
/*****************************************************************
返回數字,包含小數點
****************************************************************/
function returnNumberDot()
{
?? ? ? ?return ((event.keyCode>47 && event.keyCode<58) || event.keyCode==46);
}
/*****************************************************************
返回數字,包含包含負數
****************************************************************/
function returnNumberDot1()
{
?? ? ? ?return ((event.keyCode>47 && event.keyCode<58) || event.keyCode==46||event.keyCode==45);
}
/*****************************************************************
檢查數字,包含小數點
****************************************************************/
function CheckNumberDot(value)
{
?? ?if(value == '')
?? ? ? ?return true;
?? ? ? ?
?? ?if(value.indexOf('.') != value.lastIndexOf('.'))
?? ? ? ?return false;
?? ?return true;
}
/*****************************************************************
檢查日期,返回值:0:不是日期 1:是日期
****************************************************************/
function CheckDate(datestr)
{
?? ?if(datestr == "")
?? ? ? ?return 1;
?? ? ? ?
?? ?var lthdatestr
?? ?if (datestr != "")
?? ? ? ?lthdatestr= datestr.length ;
?? ?else
?? ? ? ?lthdatestr=0;
??
?? ?var tmpy="";
?? ?var tmpm="";
?? ?var tmpd="";
?? ?var status;
?? ?status=0;
?? ?if ( lthdatestr== 0)
?? ? ? ?return 0
?? ?for (i=0;i<lthdatestr;i++)
?? ?{?
?? ? ? ?if (datestr.charAt(i)== '-')
?? ? ? ?{
?? ? ? ? ? ?status++;
?? ? ? ?}
?? ? ? ?if (status>2)
?? ? ? ?{
?? ? ? ? ? ?return 0;
?? ? ? ?}
?? ? ? ?if ((status==0) && (datestr.charAt(i)!='-'))
?? ? ? ?{
?? ? ? ? ? ?tmpy=tmpy+datestr.charAt(i)
?? ? ? ?}
?? ? ? ?if ((status==1) && (datestr.charAt(i)!='-'))
?? ? ? ?{
?? ? ? ? ? ?tmpm=tmpm+datestr.charAt(i)
?? ? ? ?}
?? ? ? ?if ((status==2) && (datestr.charAt(i)!='-'))
?? ? ? ?{
?? ? ? ? ? ?tmpd=tmpd+datestr.charAt(i)
?? ? ? ?}
?? ?}
?? ?
?? ?year=new String (tmpy);
?? ?month=new String (tmpm);
?? ?day=new String (tmpd)
?? ?if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
?? ?{
?? ? ? ?return 0;
?? ?}
?? ?if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
?? ?{
?? ? ? ?return 0;
?? ?}
?? ?if (!((year % 4)==0) && (month==2) && (day==29))
?? ?{
?? ? ? ?return 0;
?? ?}
?? ?if ((month<=7) && ((month % 2)==0) && (day>=31))
?? ?{
?? ? ? ?return 0;
?? ?}
?? ?if ((month>=8) && ((month % 2)==1) && (day>=31))
?? ?{
?? ? ? ?return 0;
?? ?}
?? ?if ((month==2) && (day==30))
?? ?{
?? ? ? ?return 0;
?? ?}
?? ?return 1;
?? ?
?? ?
}
/*****************************************************************
?? ?檢查DropDown選中項值 id--DropDownList控件ID value--選中項值 ?mistake-輸出顯示內容
****************************************************************/
?? ?function CheckDDL(id,value,mistake)
?? ?{?
?? ? ? for(i=0;i<document.getElementById(id).options.length;i++)
?? ? {
?? ? ? ?if(document.getElementById(id).options[i].selected ==true&&document.getElementById(id).options[i].text==value )
?? ? ? ?{
?? ? ? ? ?alert(mistake);?
?? ? ? ? ?return false;
?? ? ? ? ?break;
?? ? ? ?}
?? ? }
?? ? return true;
?? ?}
?? ?
?/*****************************************************************
?? ?給DropDown副值 id--DropDownList控件ID value--選中項值 ?
****************************************************************/
?? ?//function CheckDropDown(,)
?? ?function setDropDown(id,value)
?? ?{?
?? ? ? ?for(i=0;i<document.getElementById(id).options.length;i++)
? ? ? ? {
? ? ? ? ? ?if(document.getElementById(id).options[i].text == value)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?document.getElementById(id).options[i].selected = true;
? ? ? ? ? ? ? ?break;
? ? ? ? ? ?}
? ? ? ? }
?? ?} ??
??二.分類
/*****************************************************************
****************************************************************/
function onblur_handler()
{
//
if(this.id.indexOf('txt1')>=0 || this.id.indexOf('txt2')>=0)
//
this.style.backgroundColor="#d4d0c8";
//
else
//
this.style.backgroundColor="LightBlue";
this.style.backgroundColor="White";
}
function onfocus_handler()
{
for(i=0;i<arrCtl.length;i++)
{
if(this.id == '')
{
if(this.name == arrCtl[i].name)
{
curCtlIndex = i;
break;
}
}
else
{
if(this.id == arrCtl[i].id)
{
curCtlIndex = i;
break;
}
}
}
this.style.backgroundColor="yellow";
return true;
}?
?
?
/* 中文值檢測--檢驗字符串中是否含有中文字符,若含有返回true,否則返回false*/
function hasChinese(str)
{ ?
?? ?if(str.length == 0)
?? ? ? ?return false;
?? ?for(i = 0; i < str.length; i++)
?? ?{ ?
?? ? ? ?if(str.charCodeAt(i) > 128)//128或者255?
?? ? ? ? ? ?return true;
?? ?}
?? ?return false;
}
/* 數值檢測--檢驗字符串中是否全部是數值,若是返回true,否則返回false*/
function isNumber(str)
{ ?
?? ?if(str.length == 0)
?? ? ? ?return false;
?? ?for(i = 0; i < str.length; i++)
?? ?{ ?
?? ? ? ?if(str.charAt(i) < "0" || str.charAt(i) > "9")
?? ? ? ?return false;
?? ?}
?? ?return ?true;
}
/* 電話/手機號碼檢測--檢驗是否為有效的電話或手機號碼,若有效返回true,否則返回false*/
function isTelNumber(str)
{ ?
?? ?var ?ValidChar = "1234567890-"; ?//可以自己增加可輸入值
?? ?var ?c;
?? ?if(str.charAt(0) == '-')
?? ? ? ?return false;
?? ?if(str.charAt(str.length - 1) == '-')
?? ? ? ?return ?false;
?? ?for(var i = 0; i < str.length; i++)
?? ?{ ?
?? ? ? ?c = str.charAt(i);
?? ? ? ?if(ValidChar.indexOf(c) < 0)
?? ? ? ? ? ?return false;
?? ?}
?? ?return true;
}
/* 特殊字符檢測--檢驗字符串中是否包含以下特殊字符,若含有返回true,否則返回false*/
var ErrChar = "!@#$%^&*()_+|-=\\~`;'[]{}\"':;,./<>?~!@#¥%^&×()……+|-=、〔〕{}:“;‘《》?,。、";
function hasSpecialCharacters(str)
{
?? ?for(var i=0; i < str.length; i++)
?? ?{?
?? ? ? ?if(ErrChar.indexOf(str.charAt(i)) > -1)
?? ? ? ? ? ?return true;
?? ?} ? ?
}
/* 控件最大長度檢測--檢驗該控件填寫的內容是否已經超過規定的最大長度*/
/* obj:傳入的控件(一般為TextBox), maxLength:規定的最大長度(數據庫能存放的最大字符數). 超出返回true,否則返回false*/
function isBeyondMaxLength(obj, maxLength)
{
?? ?var controlValue = obj.value;
?? ?var controlValueLength = controlValue.replace(/[^\x00-\xff]/g,'**').length
?? ?/*或者使用
?? ?var len = 0;
?? ?for (var i = 0; i < controlValue.length; i++)
?? ?{
?? ? ? ?if (controlValue.charCodeAt(i) > 255) len += 2;
?? ? ? ?else len ++;
?? ?}
?? ?var controlValueLength = len;*/
?? ?if(convtrolValueLength > maxLength)
?? ? ? ?return true;
?? ?else
?? ? ? ?return false;
}
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
