JavaScript can play a big role in web programming, write some common functions into a JavaScript class library.
Save the following code as common.js
Class library function:
Trim (STR) - Remove the space between the strings
2.Xmlencode (STR) - XML encoding for strings
3.Showlabel (STR, STR) - Mouse prompt function (display character, prompt character)
You can set the font, color, size, and prompt background color, border, etc.
4. IISEMPTY (OBJ) - Verify that the input box is empty
5. InterInt (Objstr, Sign, Zero) - Verify that it is an integer, positive integer, negative integer, and whether to include zero
6.isfloat (Objstr, Sign, Zero) - Verify that it is a floating point number, positive floating point, diverted point, and whether to include zero
7. Iisenletter (Objstr, size) - Verify that it is 26 letters, uppercase small
The source code is as follows:
/ *
Name: Common.js
Function: General JavaScript scripting function library
include:
Trim (STR) - Remove the space between the strings
2.Xmlencode (STR) - XML encoding for strings
3.Showlabel (STR, STR) - Mouse prompt function (display character, prompt character)
4. IISEMPTY (OBJ) - Verify that the input box is empty
5. InterInt (Objstr, Sign, ZERO) - Verify that it is an integer
6.isfloat (Objstr, Sign, Zero) - Verify that it is a floating point number
7. Iisenletter (Objstr, Size) - Verify that it is 26 letters
* /
/ *
============================================================================================================================================================================================================= =========
String operation
Trim (String): Removes spaces between strings
============================================================================================================================================================================================================= =========
* /
/ *
============================================================================================================================================================================================================= ======== Ltrim (String): Remove the space left
============================================================================================================================================================================================================= =========
* /
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.gen;
While (J
{
J ;
}
S = s.Substring (J, I);
}
Return S;
}
/ *
============================================================================================================================================================================================================= ==========
Rtrim (String): Remove the space on the right
============================================================================================================================================================================================================= ==========
* /
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): Remove the front and rear spaces
============================================================================================================================================================================================================= =========
* /
Function TRIM (STR)
{RTURN RTRIM (LTRIM (STR));
}
/ *
============================================================================================================================================================================================================= ==========
XMLENCode (string): XML encoding for strings
============================================================================================================================================================================================================= ==========
* /
Function Xmlencode (STR)
{
Str = Trim (STR);
Str = str.replace ("&", "&");
Str = str.replace ("<", "<");
Str = str.replace (">", ">");
Str = str.replace ("'", "'");
Str = str.replace ("/" "," ""); return STR;
}
/ *
============================================================================================================================================================================================================= =========
Verification class function
============================================================================================================================================================================================================= ==========
* /
Function ISempty (OBJ)
{
Obj = document.getlementsByname (obj) .Item (0);
IF (TRIM (Obj.Value) == "" "
{
Alert ("field can't be empty.");
IF (Obj.disabled == false && obj.readonly == false)
{
Obj.focus ();
}
}
}