Common js Methods

Source: Internet
Author: User

1: Determine the screen size
Window. screen. width
2:
For (var I = 0; I <temp. length-1; I ++ ){
NewOpt = new Option (temp [I] [0], temp [I] [1]);
Document. Form1.DropDownList3. options [I] = newOpt;
}
For (var I = 0; I <objAry. length; I ++)
{
Obj. add (new Option (objAry [I] [0] + '-' + objAry [I] [1], objAry [I] [0]);
}
Both of them can be used.

Table_tab = "<table align = 'left' width = '000000' border = '0' cellspacing = '1' cellpadding = '1'>"
For (var ji = 1; ji <FORM. OPT_AND_DESC.length; ji ++)
{
Stropt_desc = FORM. OPT_AND_DESC [ji]. value. trim ()

StrJECT_OPT = stropt_desc.substring (2, stropt_desc.indexOf ('^ '));
StrJECT_DESC = stropt_desc.substring (stropt_desc.indexOf ('^') + 2, stropt_desc.indexOf ('##'));

StrVOL_COUNT = stropt_desc.substring (stropt_desc.indexOf ('#') + 2, stropt_desc.indexOf ('$ '));
StrVOL_COUNT_UNIT = stropt_desc.substring (stropt_desc.indexOf ('$') + 2, stropt_desc.indexOf ('**'));
StrCONTENT_COUNT = stropt_desc.substring (stropt_desc.indexOf ('**') + 2, stropt_desc.indexOf ('@@'));
StrCONTENT_COUNT_UNIT = stropt_desc.substr (stropt_desc.indexOf ('@') + 2 );
StrCOUNT_UNIT = "";
If (strVOL_COUNT_UNIT.trim ()! = '') & (StrCONTENT_COUNT_UNIT.trim ()! = '')){
StrCOUNT_UNIT = strVOL_COUNT + strVOL_COUNT_UNIT.substr (2) + strCONTENT_COUNT + strCONTENT_COUNT_UNIT.substr (2 );
} Else if (strVOL_COUNT_UNIT.trim ()! = ''){
StrCOUNT_UNIT = strVOL_COUNT + strVOL_COUNT_UNIT.substr (2 );
} Else if (strCONTENT_COUNT_UNIT.trim ()! = ''){
StrCOUNT_UNIT = strCONTENT_COUNT + strCONTENT_COUNT_UNIT.substr (2 );
}
StrNUM = FORM. OPT_AND_DESC [ji]. text. trim ();

T [rowcount] = "<tr NAME = 'tr" + rowcount + "'id = 'tr" + rowcount + "'style = 'cursor: hand; 'class = 'clsgrdbody' onclick =__ grdRow_OnClick ('#95DCF9'); getdata ('"+ strNUM +"');>"
// T [rowcount] = t [rowcount] + "<TD WidTH = '000000'>" + rowcount + "</TD>"
T [rowcount] = t [rowcount] + "<TD WidTH = '000000'>" + strJECT_OPT + "</TD>"
T [rowcount] = t [rowcount] + "<TD WidTH = '000000'> <a title = '" + strJECT_DESC + "'>" + strJECT_DESC.substring (45%) + "</a> </TD>"
T [rowcount] = t [rowcount] + "<TD WidTH = '000000'>" + strCOUNT_UNIT + "</TD>"
T [rowcount] = t [rowcount] + "</tr>"

Rowcount = rowcount + 1;
}
For (I = 1; I <rowcount; I ++ ){
If (t [I]. trim ()! = '') & (T [I]! = 'Undefined '))
T_d = t_d + t [I];
}
Query_display_data.innerHTML = table_tab + t_d + "</table> ";
3: Spatial Data Group Space
Var arrEntryValue = new Array ();
// Add new elements to a data group and return the new Length Value of the group.
Var newleng = arrEntryValue. push (vEntryValue)
// Purpose: remove the null value of the Data Group
// Parameter: arry1: the number of null values to be removed. intIndex: the lower mark of the number of null values to be removed.
Function arr_Qeue (arry1, intIndex ){
If (arry1.length> 0 ){
For (var I = intIndex; I <arry1.length-1; I ++ ){
Arry1 [I] = arry1 [I + 1]
}
// Remove the last element from the group and return the element
Arry1.pop ();
}
Return arry1
}
// Purpose: When the storage is successful, empty spaces of all data groups are placed in the memory.
// Allows you to add, modify, divide, and store shards in progress.
// Parameter: arry1: number of data groups that need to be empty
Function Release_Space (arry1)
{
If (arry1.length> 0)
{
For (var I = arry1.length-1; I <arry1.length; I --)
{
If (I =-1)
{
Break;
}
Arry1.pop ()
}
}
Return arry1
}
// Determine whether the digit value is a number
Function Check_Num_Field (ObjName)
{
Var LV_Value = ObjName. value. trim ();

If (LV_Value! = '')&&(! IsNumeric (LV_Value )))
{
Alert ("Please input data! ");
ObjName. focus ();
ObjName. select ();
ObjName. value = "";
Return false;
}
Return true;
}
// Determine whether the integer value is a positive number.
Function Check_Int_Field_Plus (objF)
{
If (Check_Int_Field (objF ))
{
Var intV = objF. value * 1;
If (intV <0)
{
Alert ("the digit value cannot be smaller than 0! ")
ObjF. value = "";
ObjF. focus ();
ObjF. select ();
Return false;
}
ObjF. value = intV;
}
}
// Determine whether the integer value is an integer.
Function Check_Int_Field (ObjName)
{
Var LV_Value = ObjName. value. trim ();
If (LV_Value! = '')&&(! IsInteger (LV_Value )))
{
Alert ("Please complete the entire number! ");
ObjName. value = "";
ObjName. focus ();
Return false;
}
Return true;
}
// Determine whether the keyword is a number
Function isNumeric (strNum)
{
Var strCheckNum = strNum + "";
If (strCheckNum. length <1) // empty string
Return false;
If (isNaN (strCheckNum) // not a numeric value
Return false;

Return true;
}
// Determine whether the entire data is used.
Function isInteger (strNum)
{
Var strCheckNum = strNum * 1 + "";
If (strCheckNum. length <1) // empty string
Return false;
If (isNaN (strCheckNum) // not a numeric value
Return false;
If (parseFloat (strCheckNum)> parseInt (strCheckNum) // not an integer
Return false;
Return true;
}

// Determine whether the expiration date is valid
// Input parameter number: vobjName date object
// Whether bolChDate is the date of the nation, 0-ad date, 1-the date of the country
Function Check_Date_Field (vobjName, bolChDate)
{
Var strDay, strMonth, strYear, strCYear, strTimeAry
Var strDate, StandDate, strWeekName, datDate, intNum, strChangeDate
Var resStr = "";
 
StrDate = vobjName. value. trim ();
If (strDate = "") return; // if the date is null, do not
// If the date is the date of the nation, the first digit is the date of the year.
If (bolChDate = 1)
{
If (strDate. indexOf ("-")> 0)
StrDate = (strDate. substring (0, strDate. indexOf ("-") * 1 + 1911 ). toString () + (strDate. substring (strDate. indexOf ("-"), strDate. length )). toString ()
Else
If (strDate. indexOf (".")> 0)
StrDate = (strDate. substring (0, strDate. indexOf (". ") * 1 + 1911 ). toString () + (strDate. substring (strDate. indexOf (". "), strDate. length )). toString ()
Else
If (strDate. indexOf ("/")> 0)
StrDate = (strDate. substring (0, strDate. indexOf ("/") * 1 + 1911 ). toString () + (strDate. substring (strDate. indexOf ("/"), strDate. length )). toString ()
Else
StrDate = (strDate. substring (0, strDate. length-4) * 1 + 1911 ). toString () + (strDate. substring (strDate. length-4, strDate. length )). toString ()
}
// Set the date to "1997/5/6"
// XXXX-XX-XX
If (strDate. indexOf ("-")! = 0)
{ResStr = "";
For (var I = 0; I <strDate. length; I ++)
ResStr = resStr + (strDate. substring (I, I + 1). replace ('-','/'));
StrDate = resStr;
}
// XXXX. XX. XX
If (strDate. indexOf (".")! = 0)
{ResStr = "";
For (var I = 0; I <strDate. length; I ++)
ResStr = resStr + (strDate. substring (I, I + 1). replace ('.','/'));
StrDate = resStr;
}
// XXXXXXXX
If (strDate. indexOf ("/") <= 0)
{StrDate = (strDate + '000000000a'). substring (0, 8)
StrDate = strDate. substring () + "/" + strDate. substring () + "/" + strDate. substring (6, 8 );
}
// Determine whether the expiration date is valid
If (! IsDate (strDate ))
{
Alert ("please refer to the date, in the format of year, month, day !! ");
VobjName. value = "";
VobjName. focus ();
Return;
}
If (bolChDate = 1)
{
StrYear = '000' + (strDate. substring (1911) * 1-). toString ()
StrYear = strYear. substring (strYear. length-3, strYear. length)
StrDate = strYear. toString () + (strDate. substring (4, strDate. length). toString ()
}
VobjName. value = strDate;
}
// Determine whether the expiration date is valid
Function IsDate (str)
{
Var r = str. match (/^ (\ d {}) (-| \/) (\ d {}) \ 2 (\ d {}) $ /);
If (r = null) return false;
Var d = new Date (r [1], r [3]-1, r [4]);
Return (d. getFullYear () = r [1] & (d. getMonth () + 1) = r [3] & d. getDate () = r [4]);
}
// The regular expression for removing spaces from a string
String. prototype. trim = function ()
{
Return this. replace (/(^ \ s *) | (\ s * $)/g ,'');
}
// Check validity of the time bit value
Function Check_Time_Field (objtime, strH)
{
Var strTime
Var resStr = "";
Var VL
Var vM
Var
StrTime = objtime. value. trim ();
If (strTime = "") return; // if the time is null, do not
// Set the time to "12:00:00"
// XX. XX. XX
ResStr = "";
For (var I = 0; I <strTime. length; I ++)
ResStr = resStr + (strTime. substring (I, I + 1). replace ('.',':'));
StrTime = resStr;
// XX
ResStr = "";
For (var I = 0; I <strTime. length; I ++)
ResStr = resStr + (strTime. substring (I, I + 1). replace ('',':'));
StrTime = resStr;
// XX-XX-XX
ResStr = "";
For (var I = 0; I <strTime. length; I ++)
ResStr = resStr + (strTime. substring (I, I + 1). replace ('-',':'));
StrTime = resStr;
// XXXXXXXX
If (strTime. indexOf (":") <= 0)
{
If (strTime. length = 1)
StrTime = "0" + "+ strTime +": 00: 00 ";
Else {
StrTime = (strTime + '123'). substring (000000)
StrTime = strTime. substring () + ":" + strTime. substring () + ":" + strTime. substring );
}
}
// XX: XX
If (strTime. lastIndexOf (":")> 0 & strTime. lastIndexOf (":") <= 2)
StrTime = strTime + ': 00 ';

Var strTimeArry2 = strTime. split (":");
FLAC = strTimeArry2 [0];
VM = strTimeArry2 [1];
VS = strTimeArry2 [2];
If (strTimeArry2.length = 2)
VS = "00 ";
If (! (IsNaN (VL) | isNaN (vM) | isNaN ()))
{
If (VL> = 24) VL = vH-24;
If (vM> = 60) vM = vM-60;
If (vS> = 60) vS = vS-60;
Consecutive hours = "00" + (consecutive hours * 1). toString ()
Consecutive hours (hours) = consecutive days (hours)
VM = "00" + (vM * 1). toString ()
VM = vM. substring (vM. length-2, vM. length)
VS = "00" + (vS * 1). toString ()
VS = vS. substring (vS. length-2, vS. length)
}
StrTime = VL + ":" + vM + ":" +;
 
// Judge the time
If (! IsTime (strTime ))
{
Alert ("loading time! ");
Objtime. value = "";
Return;
}
If (strH = 0)
StrTime = strTime. substring (0, 5 );
Objtime. value = strTime;
}
// Validity of the checking time
Function IsTime (strTime)
{
Var strHours;
Var strMinutes;
Var strSeconds;
Var strTimeArry3 = strTime. split (":"); // use ":" To divide data into groups
If (strTimeArry3.length! = 3) // if it is not a time-and-second-level standard format, no score is given.
Return false;
StrHours = strTimeArry3 [0];
StrMinutes = strTimeArry3 [1];
StrSeconds = strTimeArry3 [2]
If (isNaN (strHours) | isNaN (strMinutes) | isNaN (strSeconds ))
Return false;
If (strTimeArry3 [0]. length> 2 | strTimeArry3 [1]. length> 2 | strTimeArry3 [2]. length> 2)
Return false;
If (strHours> 23 | strHours <0 | strMinutes> 59 | strMinutes <0 | strSeconds> 59 | strSeconds <0)
Return false;
Return true;
}
// Modify the format of text (Table 0 has no shadow)
Function disable (txtname, val)
{
If (txtname! = Null & txtname! = "" & Txtname! = ""){
If (val = 0 ){
If (txtname. type = 'text '){
Txtname. style. borderStyle = "groove"
Txtname. readOnly = true
} Else {
Txtname. disabled = true
}
} Else {
If (txtname. type = 'text '){
Txtname. style. borderStyle = ""
Txtname. readOnly = false
} Else {
Txtname. disabled = false
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.