Home > Web Front-end > JS Tutorial > Commonly used js scripts_form effects

Commonly used js scripts_form effects

WBOY
Release: 2016-05-16 19:23:33
Original
734 people have browsed it

These are all used at work, I hope you can use them in the future

// "":,.! ; typeof(objectName) == ''undefined''
//Define constants ---------------------------------- ----------------------------------------
var TxtReadOnlyBgColor = "#EEEEEE " // Background color when the input box has a Readonly attribute
/*====================Function Description Part 6======== ================================================== ================================================== ===========
1. JIsNumberText(txtName,sLabel) ◆→Check whether the value of the specified Text input box is numerical data Example ◆→if(!JIsNumberText(txtGrade,"Grade") ) return;
2. JIsNumber(sNumber) ◆→Check whether the sNumber string is numeric data
3. JFormatNumber(rNumber,iDec) ◆→Format the value rNumber with iDec decimal point for formatted output
4. JGetDays(iYear,iMonth) ◆→Used to find the number of days in iMonth of iYear
5. JIsDate(sDate) ◆→Check whether the sDate string is date type data
6. JIsTime(sTime) ◆→ Check whether the sTime string is time data
7. JFormatDate(sDate,sSplit) ◆→Convert the date string sDate into a date string in the standard format "YYYY-MM-DD";
8. JFormatTime( sTime,sSplit) ◆→Convert the time string sTime into a time string in the standard format "HH:MM:SS";
9. JCheckTxtIsDate(txtName,sLabel) ◆→Check whether the data in the text box txtName is a date Type data
10. JCheckTxtIsTime(txtName,sLabel) ◆→Check whether the data in the text box txtName is time type data
11. JGetCurrentDate() ◆→Get the current date of the system (the date format is "YYYY-MM -DD")
12. JGetCurrentCnDate() ◆→ Get the current date of the system (the date format is "MM, DD, YYYY")
13. JGetCurrentTime() ◆→ Get the current time of the system (time format is "HH:MM:SS")
14. JInitYearSelect(iBefore,iAfter,selName) ◆→Initialize the relevant year Select (drop-down box)
15. JInitDateSelect(iYear,iMonth,selName) ◆→Initialize the iYear year Option in the Select of iMonth date,
16. JCorrectChar(txtName,sLabel,sCorrectStr) ◆→ Determine whether the value of the Text text input box is in the legal string sCorrectStr
17. JTextEmpty(txtName,sLabel) ◆→Determine whether the value of a text input box txtName is empty;
18. JLTrim(sString) ◆→Truncate the leading spaces of the sString string
19. JRTrim(sString) ◆→Truncate the sString string Truncate trailing spaces
20, JTrim(sString) ◆→Truncate spaces before and after the sString string
21, JLen(sString) ◆→Test the length of the string sString;
22, JCopy(sString ,iStart,iCount) ◆→Copy the string sString starting from iStart iCount lengths
23. JSplitId(sId_Name) ◆→Extract the data in []
24. JToUpperCase() ◆→Automatically enter the text box Convert the content into uppercase characters
25. JToLowerCase() ◆→ Automatically convert the content in the input text box into lowercase characters
26. JNumberText() ◆→ Limit the text input box to only the number "0" to "9",".","-"
27. reOpenWin(sUrl,pw,ph) ◆→Open a centered window and return the name of the opened window
28. reOpenWinSc(sUrl,pw, ph) ◆→Open a centered window with a vertical scroll bar, and return the name of the opened window
29. checkLen(obj,iLen,desc) ◆→Check whether the input content length is the specified length
30. winCenter() ◆→Center the window
31. selNotEmpty(obj,sLabel) ◆→One of the drop-down boxes must be selected
32. fucusWin(winName) ◆→The focus is set on the incoming window
33. closeWin(winName) ◆→Close the window
34.JNotInputEnter() ◆→Restrict the input of the Enter key
35. JIntNumText() ◆→Restrict only integer data to be entered in the text input box [0- 9] Example ◆→
36. JInputLetter() ◆→ Limit the text input box to only letters [A-Za-z]
37. JInputTel() ◆→ Limit the text input box to only letters Can input phone content [0-9], -, (),
38, JInputDate() ◆→ Only date content can be entered in the text input box [0-9], -, /,
39, JIsIntNum() ◆→ Determine whether the content of the passed file box is an integer
================================ ================================================== ==================*/

// ====================== ================================================== ==========
// Part 1 Numerical Functions
// ============================ ================================================== ======

//------------------------------------ -----------------------------------------------
//1.1 This function is used to check whether the value of the specified Text input box is numerical data
// txtName: Text input box object
// sLabel: The label name of the text input box; such as: age, quantity, etc.
//--------------------------------------------- ---------------------------------------------
function JIsNumberText(txtName,sLabel)
{
var strTemp = "";

if (isNaN(txtName.value) || (txtName.value.length == 0))
{
strTemp = """ sLabel "" must be numeric data.";
window.alert(strTemp);
txtName.value = "0";
txtName.select();
return false;
}
else
{
return true ;
}
}

//--------------------------- --------------------------------------------------
//1.2 This function is used to check whether the sNumber string is numeric data
//-------------------------- -------------------------------------------------- --
function JIsNumber(sNumber)
{
if (isNaN(sNumber) || (sNumber.length == 0))
{ return false ; }
else
{ return true ; }
}

// ---------------------------------- ---------------------------------------------
//1.3 version The function is used to format the value rNumber with iDec decimal points for formatted output
// ---------------------------------- -----------------------------------------------
function JFormatNumber(rNumber,iDec)
{
var sResult,sTemp,i;
var iInt; // Integer part
var iDig; // Decimal part

if (iDec {
sResult = Math.round(rNumber) ;
}
else
{
iInt = Math.floor (rNumber) ;
iDig = rNumber - iInt ;
iDig = Math.round(iDig * Math.pow(10,iDec)) ;
if (iDig >= Math.pow(10,iDec) ) // When the decimal point part is rounded and carried to the integer digit
{
iInt = iInt 1 ;
iDig = 0 ;
}
if (iDig == 0) // When the decimal point The part that is 0 is complemented with 0
{
sTemp = "" ;
for (i = 1;i sResult = iInt "." sTemp ;
}
else
{
if (iDig {
sTemp = "" ;
for (i = 1; i {
if (iDig }
sResult = iInt "." sTemp iDig ;
}
else
{
sResult = iInt "." iDig ;
}
}
}
return sResult ;
}


// ================================= =================================================
//Part 2 Date related functions
// ===================================== ===============================================

//------------------------------------------------ -------------------------------------
//2.1 This function is used to solve The number of days in iMonth in iYear
//--------------------------------------------- ---------------------------------------------
function JGetDays(iYear ,iMonth)
{
var StartDate,EndDate,iStart,iEnd,iDays;
switch (iMonth)
{
case 1: return 31;
case 3: return 31;
case 5: return 31 ;
case 7: return 31 ;
case 8: return 31 ;
case 10: return 31 ;
case 12: return 31 ;
case 4 : return 30;
case 6: return 30;
case 9: return 30;
case 11: return 30;
case 2:
StartDate = new Date(iYear,1,1 );
iStart = StartDate.getTime();
EndDate = new Date(iYear,2,1);
iEnd = EndDate.getTime();
iDays = iEnd - iStart;
iDays = iDays / 1000 / 60 / 60 / 24 ;
return Math.round(iDays) ;
break ;
}
}

//----- -------------------------------------------------- -----------------------
//2.2 This function is used to check whether the sDate string is date data
//--- -------------------------------------------------- ------------------------
function JIsDate(sDate)
{
var sArray,sTemp;
var i ,i1 = 0,i2 = 0 ;
var iYear,iMonth,iDay ;

sArray = sDate.split("") ;
if (sDate == "")
{
return false ;
}
else
{
for (i = 0; i {
if ((i1 == 0) && (sArray[i] == "-")) { i1 = i ; continue ;} 
if (i1 > 0 && i2 == 0 && sArray[i] == "-" ) { i2 = i; break ; } 


if (i1 > 0 && i2 > 0)
{
sTemp = JCopy(sDate,0,i1) ;
if (JIsNumber(sTemp)) //判断年是否是数字型数据
{ iYear = parseInt(sTemp,10) ; } 
else
{ return false ;}

sTemp = JCopy(sDate,i1   1, i2 - i1 - 1) ;
if (JIsNumber(sTemp)) 

iMonth = parseInt(sTemp,10) ; 
if (iMonth = 13)
{ return false ;}

else
{ return false ;}

sTemp = JCopy(sDate,i2   1,sDate.length - i2   1) ;
if (JIsNumber(sTemp)) 

iDay = parseInt(sTemp,10) ; 
if (iDay  JGetDays(iYear,iMonth))
{ return false ;}

else
{ return false ;}

}
else
{
return false ;
}
}
return true ;
}

//------------------------------------------------------------------------------
//2.2 本函数用于检查sTime字符串是否是时间型数据
//------------------------------------------------------------------------------
function JIsTime(sTime)
{
var sArray,sTemp ;
var i,i1 = 0,i2 = 0 ;
var iHour,iMin,iSecond ;

sArray = sTime.split("") ;
if (sTime == "") 
{
return false ;
}
else
{
for (i = 0; i {
if ((i1 == 0) && (sArray[i] == ":")) { i1 = i ; continue ;} 
if (i1 > 0 && i2 == 0 && sArray[i] == ":" ) { i2 = i; break ; } 


if (i1 > 0)
{
sTemp = JCopy(sTime,0,i1) ;
if (JIsNumber(sTemp)) //判断年是否是数字型数据

iHour = parseInt(sTemp,10) ; 
if (iHour = 24) { return false ;}

else
{ return false ;}

if (i2 > 0)
{
sTemp = JCopy(sTime,i1   1, i2 - i1 - 1) ;
if (JIsNumber(sTemp)) 

iMin = parseInt(sTemp,10) ; 
if (iMin = 60) { return false ;}

else
{ return false ;}

sTemp = JCopy(sTime,i2   1,sTime.length - i2   1) ;
if (sTemp != "")
{
if (JIsNumber(sTemp)) 

iSecond = parseInt(sTemp,10) ; 
if (iSecond = 60) { return false ;}

else
{ return false ;}


}
else
{
sTemp = sTime ;
if (JIsNumber(sTemp)) //判断年是否是数字型数据

iHour = parseInt(sTemp,10) ; 
if (iHour = 24) { return false ;}

else
{ return false ;}
}
}
return true ;
}


//--------------------------------------- ---------------------------------------------
//2.3 version The function is used to convert the date string sDate into a date string in the standard format "YYYY-MM-DD";
// The parameter sSplit is the split string;
// -------- -------------------------------------------------- --------------------------
function JFormatDate(sDate,sSplit)
{
var sArray ;
var i, i1 = 0,i2 = 0;
var iYear,iMonth,iDay;

sArray = sDate.split("");

for (i = 0; i {
if ((i1 == 0) && (sArray[i] == "-")) { i1 = i ; continue ;}
if (i1 > 0 && i2 == 0 && sArray[i] == "-" ) { i2 = i; break ; }
}

if (i1 > 0 && i2 > 0)
{
iYear = parseInt(JCopy(sDate,0,i1),10)
iMonth = parseInt(JCopy(sDate,i1 1, i2 - i1 - 1),10)
iDay = parseInt(JCopy(sDate ,i2 1,sDate.length - i2 1),10)
}

sTemp = iYear sSplit ;
if (iMonth else { sTemp = sTemp iMonth sSplit ;}
if (iDay else { sTemp = sTemp iDay ;}
return sTemp ;
}


// ----------------------------------------------- -----------------------------------------------
//2.3 This function is used to convert the time string sTime into a time string in the standard format "HH:MM:SS";
// The parameter sSplit is the split string;
// ------- -------------------------------------------------- ------------------------
function JFormatTime(sTime,sSplit)
{
var sArray ;
var i ,i1 = 0,i2 = 0;
var iHour,iMin,iSecond;

sArray = sTime.split("");

for (i = 0; i {
if ((i1 == 0) && (sArray[i] == ":")) { i1 = i ; continue ;}
if (i1 > 0 && i2 == 0 && sArray[i] == ":" ) { i2 = i; break ; }
}

if (i1 > 0 && i2 > 0) // time/ Both minutes and seconds have values
{
iHour = parseInt(JCopy(sTime,0,i1),10);
iMin = parseInt(JCopy(sTime,i1 1, i2 - i1 - 1), 10);
iSecond = parseInt(JCopy(sTime,i2 1,sTime.length - i2 1),10);
}
if (i1 > 0 && i2 {
iHour = parseInt(JCopy(sTime,0,i1),10);
iMin = parseInt(JCopy(sTime,i1 1,sTime.length - i1 1),10 );
iSecond = 0;
}
if (i1{
iHour = parseInt(sTime,10);
iMin = 0 ;
iSecond = 0 ;
}

if (! JIsNumber(iHour)) { iHour = 0; }
if (! JIsNumber(iMin)) { iMin = 0 ; }
if (! JIsNumber(iSecond)) { iSecond = 0 ; }

if (iHour else { sTemp = iHour sSplit ; }
if (iMin else { sTemp = sTemp iMin sSplit ;}
if (iSecond else { sTemp = sTemp iSecond ;}
return sTemp ;
}

//------------------------------------------------ ------------------------------------
//2.4 This function is used to check the text box txtName Whether the data inside is date data
//---------------------------------------- -------------------------------------
function JCheckTxtIsDate(txtName,sLabel )
{
var sValue ;

sValue = JLTrim(JRTrim(txtName.value)) ;
if (JIsDate(sValue))
{
txtName.value = JFormatDate(sValue,"-");
return true;
}
else
{
strTemp = """ sLabel "" The value is not a legal date data. " unescape("nn");
strTemp = strTemp "The legal date data format is: or . " unescape("nn");
strTemp = strTemp "such as: Can be written as or "
window.alert(strTemp);
txtName.select();
txtName.focus();
return false;
}.
}

//----------------------------------------- -------------------------------------
//2.4 This function is used to Check whether the data in the text box txtName is time type data
//--------------------------------- ---------------------------------------------
function JCheckTxtIsTime (txtName,sLabel)
{
var sValue ;

sValue = JLTrim(JRTrim(txtName.value)) ;
if (JIsTime(sValue))
{
txtName.value = JFormatTime(sValue,":");
return true;
}
else
{
strTemp = """ sLabel "" The value is not legal Time data. " unescape("nn");
strTemp = strTemp "The legal time data format is: or . " unescape("nn");
strTemp = strTemp "For example: can be written as or ."
window.alert(strTemp);
txtName.select();
txtName.focus();
return false;
}
}


//--------------------------------------------- ------------------------------------
//2.5 This function is used to obtain the current system Date (the date format is "YYYY-MM-DD")
//-------------------------------- --------------------------------------------------
function JGetCurrentDate()
{
var iYear,iMonth,iDate,Today,sDate;

Today = new Date();
iYear = Today.getYear();
iMonth = Today.getMonth() 1 ;
iDate = Today.getDate() ;

sDate = String(iYear) ;
if (iMonth {
sDate = sDate "-0" String(iMonth) ;
}
else
{
sDate = sDate "-" String(iMonth) ;
}
if (iDate {
sDate = sDate "-0" String(iDate) ;
}
else
{
sDate = sDate "-" String(iDate) ;
}
return sDate ;
}

// ---------------------------------- -------------------------------------------------- -
//2.6 This function is used to obtain the current date of the system (the date format is "MM, DD, YYYY")
//---------------- -------------------------------------------------- ----------------
function JGetCurrentCnDate()
{
var iYear,iMonth,iDate,Today,sDate;

Today = new Date() ;
iYear = Today.getYear() ;
iMonth = Today.getMonth() 1 ;
iDate = Today.getDate() ;

sDate = String(iYear) ;
if (iMonth {
sDate = sDate "Year 0" String(iMonth) ;
}
else
{
sDate = sDate "Year" String(iMonth) ;
}
if (iDate {
sDate = sDate "Month 0" String(iDate) ;
}
else
{
sDate = sDate "month" String(iDate);
}
sDate = sDate "day";
return sDate;
}
//-------- -------------------------------------------------- --------------------------
//2.5 This function is used to obtain the current time of the system (the time format is "HH:MM:SS" )
// ----------------------------------------------- ---------------------------------------------
function JGetCurrentTime()
{
var iHour,iMin,iSecond,Today,sTime;

Today = new Date();
iHour = Today.getHours();
iMin = Today.getMinutes();
iSecond = Today.getSeconds() ;

sTime = "" ;

if (iHour { sTime = "0" String(iHour) ; }
else
{ sTime = String(iHour) ; }

if (iMin { sTime = sTime ":0" String(iMin) ; }
else
{ sTime = sTime ":" String(iMin) ; }

if (iSecond { sTime = sTime ":0" String(iSecond) ; }
else
{ sTime = sTime ":" String(iSecond) ; }
return sTime ;
}


//---------------- -------------------------------------------------- --------
//2.7 This function is used to initialize the relevant year Select,
// The parameter iBefore represents the number of years starting from the current year;
// iAfter represents the number of years forward from the current year; The number of years starting from the current year;
//------------------------------------------------ ------------------------------------------
function JInitYearSelect(iBefore,iAfter ,selName)
{
var iYear,i,optItem;
var dDate = new Date()

for (i = selName.length; i >= 0; i --)
{
selName.options[i] = null;
}

iYear = dDate.getYear();
for (i = iYear - iBefore; i {
optItem = document.createElement("OPTION") ;
optItem.text = i ;
optItem.value = i ;
if (i == iYear) { optItem.selected = true ;}
selName.add(optItem);
}
}

// ----------------------------------------------------------------------------
//2.8 本函数用于初始化iYear年iMonth月的日期的Select中的Option,
//-----------------------------------------------------------------------------
function JInitDateSelect(iYear,iMonth,selName) 
{
var iDays,i,optItem,sTemp ;

for (i = selName.length ; i >= 0 ; i --)
{
selName.options[i] = null;
}

iDays = JGetDays(parseInt(iYear),parseInt(iMonth)) ;
for (i = 1; i { 
optItem = document.createElement("OPTION") ; 
if (i >= 10)
{
optItem.text = i ; 
optItem.value = i ; 
}
else
{
optItem.text = "0"   i.toString() ;
optItem.value = "0"   i.toString() ;
}
if (i == iYear   1) { optItem.selected = true ;}
selName.add(optItem); 

}


// ==================================================================================
// 第三部分 输入合法性检查函数
// ==================================================================================

// ----------------------------------------------------------------------------------
// 3.1 本函数用于判断Text文本输入框的值是否在合法字符串sCorrectStr中
// ----------------------------------------------------------------------------------
function JCorrectChar(txtName,sLabel,sCorrectStr)
{
var i,CheckChar ;

for(i = 0 ; i {
CheckChar = txtName.value.charAt(i) ;
if (sCorrectStr.indexOf(CheckChar) == -1)
{
strTemp = "“"   sLabel   "”中含有非法字符。"   unescape("nn") ;
strTemp = strTemp   "合法的字符集是:。" ;
window.alert(strTemp) ;
txtName.select() ;
txtName.focus() ;
return false ;
}
}
return true ; 
}

// -----------------------------------------------------------------------------------
// 3.2 本函数用于判断一个文本输入框txtName的值是否为空;
// -----------------------------------------------------------------------------------
function JTextEmpty(txtName,sLabel)
{
var strTemp = "" ; 

strTemp = JRTrim(JLTrim(txtName.value)) ;
if (strTemp =="")
{
strTemp = "“"   sLabel   "”不能为空,请输入正确的“"   sLabel   "”。";
window.alert(strTemp);
txtName.focus();
return true;
}
return false;
}

// = ================================================== ===============================
//Part 4 String Related Functions
// == ================================================== ==============================


// ---------- -------------------------------------------------- --------------------------
//4.1 This function is used to truncate the leading spaces of the sString string
// -- -------------------------------------------------- ----------------------------------
function JLTrim(sString)
{
var sStr,i ,iStart,sResult = "";

sStr = sString.split("");
iStart = -1 ;
for (i = 0 ; i {
if (sStr[i] != " ")
{
iStart = i;
break;
}
}
if (iStart == - 1) { return "" ;} //Indicates that all characters in sString are spaces, then return an empty string
else { return sString.substring(iStart) ;}
}

// -------------------------------------------------- ----------------------------------
//4.2 This function is used to add spaces after the sString string. Cut off
//------------------------------------------------ ----------------------------------------
function JRTrim(sString)
{
var sStr,i,sResult = "",sTemp = "" ;

// if (sString.length == 0) { return "" ;} // The parameter sString is an empty string

sStr = sString.split("");
for (i = sStr.length - 1; i >= 0; i --) // Reverse the string
{
sResult = sResult sStr[i];
}
sTemp = JLTrim(sResult); // Truncate spaces before the string

if (sTemp == "") { return " " ; }

sStr = sTemp.split("");
sResult = "" ;
for (i = sStr.length - 1; i >= 0; i--) / / Reverse the processed string
{
sResult = sResult sStr[i];
}
return sResult;
}

// -- -------------------------------------------------- --------
//This function is used to truncate the leading and trailing spaces of the sString string
// ------------------- ------------------------------------------
function JTrim(sString)
{
var strTmp ;

strTmp = JRTrim(JLTrim(sString)) ;

return strTmp ;
}

// ---- -------------------------------------------------- -----------------------
//4.3 This function is used to test the length of the string sString;
// Note: For this function Say, 1 Chinese character represents 2 units of length;
// ---------------------------------- ------------------------------------------
function JLen(sString)
{
var sStr,iCount,i,strTemp;

iCount = 0;
sStr = sString.split("");
for (i = 0; i {
strTemp = escape(sStr[i]);
if (strTemp.indexOf("%u",0) == -1) // Indicates that it is a Chinese character
{
iCount = iCount 1;
}
else
{
iCount = iCount 2;
}
}
return iCount;
}

//--------------------------------------------- ----------------------------------
//4.4 This function is used to copy the string sString from iStart Start iCount length
// Note: When using this function, the length units of iStart and iCount are all English character lengths;
// That is, 1 English letter represents 1 unit length, and 1 Chinese character represents 2 unit length.
// When the last character copied is only half a Chinese character, it is discarded;
// When the position of iStart is the last half of a Chinese character, iStart will start from the next valid character ;iStart starts from 0
//---------------------------------------- -------------------------------------
function JCopy(sString,iStart,iCount)
{
var sStr,i,j,strTemp = "",sResult = "";
var iResultLen = 0 ;

if (iStart if (iCount
sStr = sString.split("");

j = 0 ;
for (i = 0 ; i {
strTemp = escape(sStr[i]);
if (j >= iStart) // Copy the string
{
sResult = sResult sStr[i];
if (strTemp.indexOf( "%u",0) == -1) // The copied non-Chinese characters
{
iResultLen = iResultLen 1 ;
j = j 1 ;
}
else
{
iResultLen = iResultLen 2 ;
j = j 2 ;
}

if (iResultLen if (iResultLen > iCount) // The last character is only half a Chinese character, so it is discarded;
{
sResult = sResult.substring(0,sResult.length - 1);
break;
}
if (iResultLen = iCount) { break ; }
}
else
{
if (strTemp.indexOf("%u",0) == -1) // Not Chinese characters
{ j = j 1 ; }
else
{ j = j 2 ; }
}
}
return sResult ;
}

/ /------------------------------------------------ -------------
// This function is used to extract data within []
// -------------- ---------------------------------------------
function JSplitId (sId_Name)
{
var sStr,i,sResult = "" ;
var iStart = 0 ,iEnd = 0 ;

sStr = sId_Name.split("");
for (i = 0; i{
if (sStr[i] == "[")
{
iStart = i 1;
break ;
}
}

for (i = 0; i{
if (sStr[i] == "]")
{
iEnd = i - 1 ;
break ;
}
}

if ((iStart > 0) && (iEnd > 0) && (iEnd >= iStart) )
{
sResult = JCopy(sId_Name,iStart,iEnd - iStart 1) ;
}
else
{
sResult = "" ;
}
return sResult ;
}


// ================================= ===============================
//This function is used to automatically convert the content in the input text box into Uppercase characters
// ============================================= =====================
function JToUpperCase()
{
if ((window.event.keyCode >= 97) && (window .event.keyCode {
window.event.keyCode = window.event.keyCode - 32 ;
}
}

// ==== ================================================== ==========
// This function is used to automatically convert the content in the input text box into lowercase characters
// ============== ==================================================
function JToLowerCase()
{
if ((window.event.keyCode >= 65) && (window.event.keyCode {
window.event.keyCode = window.event.keyCode 32 ;
}
}

// ========================== ======================================
// This function is used to limit text input Only numbers "0" to "9", "." can be entered in the box
// ============================== ====================================
function JNumberText()
{
if (!(((window.event.keyCode >= 48) && (window.event.keyCode || (window.event.keyCode == 13) || (window.event.keyCode == 46)))
{
window.event.keyCode = 0 ;
}
}

// ============= ================================================== =============================
// This function is used to open a centered window and return the name of the opened window , the effect is better when used together with fucusWin() and closeWin()
// Where sUrl: relative address, pw: width; ph: height
// ============= ================================================== ============================
function reOpenWin(sUrl,pw,ph){
var sFeature,sw=pw ,sh=ph;
sFeature="width=" sw ",height=" sh ",top=" ((window.screen.height-sh)/2-15) ",left=" ((window. screen.width-sw)/2-5) ",";
return window.open(sUrl,"",sFeature);
}
// ============================================= ================================================== ==========
// This function is used to open a centered window with a vertical scroll bar, and returns the name of the opened window. It has better effect when used together with fucusWin() and closeWin() Jia
// ============================================== ================================================== ============
function reOpenWinSc(sUrl,pw,ph){
var sFeature,sw=pw,sh=ph;
sFeature="width=" sw " ,height=" sh ",top=" ((window.screen.height-sh)/2-15) ",left=" ((window.screen.width-sw)/2-5) ",scrollbars=yes ";
return window.open(sUrl,"",sFeature);
}


// ================== ================================================== ======================================
// This function is used to detect the input Content length is the specified length.
// ============================================= ================================================== ===========
function checkLen(obj,iLen,desc){
if(JLen(obj.value)>iLen){
alert( """ desc "" The length cannot exceed 〖" iLen "〗 bytes, each Chinese character is two bytes! ");
obj.select();
return false;
}
return true;
}

// ========================================= ================================================== ================
// This function is used to center the window
// ================== ================================================== ======================================
function winCenter(){
window .moveTo((screen.width-document.body.clientWidth-10)/2,(screen.height-document.body.clientHeight-30)/2);
}

// == ================================================== ================================================== ===
// One of the detection drop-down boxes must be selected
// ================================ ================================================== ==========================
function selNotEmpty(obj,sLabel){
var strTemp = "" ;
strTemp = JTrim(obj.value);
if (strTemp == ""){
strTemp = """ sLabel "" cannot be empty, please select the correct "" sLabel "".";
window.alert(strTemp);
obj(0).selected=true;
return true;
}
return false;
}

// ================================================ ================================================== =======
// Focus is set on the incoming window
// =========================== ================================================== ===============================
function fucusWin(winName){
try{
if( winName!=null){
winName.focus();
var sWinName=(winName.name).toString;
}
}
catch(e){
// alert(e); //Ignore errors
}
}

// ========================== ================================================== ==============================
//Close window
// ======== ================================================== ================================================
function closeWin(winName){
try{
if(winName!=null){
winName.close();
}
}
catch(e){
}
}

// ==================================== ================================================== ===================
//Restrict input of Enter key
// ================ ================================================== ========================================
function JNotInputEnter(){
if(window.event.keyCode=13) window.event.keyCode=0;
}

// =================== =============================================
// This function is used to limit the text input box to only input integer data [0-9]
// =========================== =======================================
function JIntNumText(){
if (!(((window.event.keyCode >= 48) && (window.event.keyCode || (window.event.keyCode == 13)))
{
window.event.keyCode = 0 ;
}
}

// ========================== =======================================
// This function is used to limit text Only letters [A-Za-z] can be entered in the input box
// =============================== =================================
function JInputLetter(){
if ( !((( window.event.keyCode >= 65) && (window.event.keyCode || ((window.event.keyCode >= 97) && (window.event.keyCode || (window.event.keyCode == 13)))
{
window.event.keyCode = 0 ;
}
}

// === ================================================== ===========
// This function is used to limit the text input box to only input phone content [0-9], -, (),
// ==== ================================================== ==========
function JInputTel(){
if (!(((window.event.keyCode >= 48) && (window.event.keyCode || (window.event.keyCode == 45)|| (window.event.keyCode == 13)
|| (window.event.keyCode == 40)|| (window.event.keyCode == 41)))
{
window.event.keyCode = 0 ;
}
}

// =============== =================================================
// This function is used to limit the text input box to only input date content [0-9], -, /,
// ================= ===============================================
function JInputDate(){
if ( !(((window.event.keyCode >= 48) && (window.event.keyCode || (window.event.keyCode == 45)
|| (window.event.keyCode == 47)|| (window.event.keyCode == 13)))
{
window.event.keyCode = 0 ;
}
}

// ========================================== ========================
// This function is used to determine whether the content of the passed file box is an integer
// == ================================================== ============
function JIsIntNum(Oject,sLabel){
var vNum = /^[d] $/;
if(!vNum.test(Oject.value )){
var strTemp = """ sLabel "" must be an integer, please enter the correct "" sLabel "".";
alert(strTemp);
Oject.value=0;
Oject.select();
return true;
}
return false;
}

reOpenWin 함수(sUrl,pw,ph){
var sFeature,sw=pw,sh=ph; 
sFeature="width=" sw ",height=" sh ",top=" ( (window.screen.height-sh)/2-15) ",left=" ((window.screen.width-sw)/2-5) ","; 
return window.open(sUrl,"" ,sFeature);

기능 reOpenWinSc(sUrl,pw,ph){
var sFeature,sw=pw,sh=ph; 
sFeature="width=" sw ", height=" sh ",top=" ((window.screen.height-sh)/2-15) ",left=" ((window.screen.width-sw)/2-5) ",scrollbars=yes" ; 
window.open(sUrl,"",sFeature)


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template