Common javascriptfunction code _ javascript skills
Source: Internet
Author: User
Some common javascript Functions are used as reference for learning. // mhHover ('start ID name', 'nth TD tag', 'style name ')
Program code
Function mhHover (tbl, idx, cls ){
Var t, d;
If (document. getElementById) t = document. getElementById (tbl );
Else t = document. all (tbl );
If (t = null) return;
If (t. getElementsByTagName) d = t. getElementsByTagName ("TD ");
Else d = t. all. tags ("TD ");
If (d = null) return;
If (d. length <= idx)
Return;
D [idx]. className = cls;
}
// Drop-down menu to show hidden IDS
// Usage
// OnChange = "OptionNumber_change ('form name', 'Id with the same name (sequence number automatically taken )')"
// Note: the Value of the form must be a number.
Program code
Function OptionNumber_change (selObj, strOpt)
{
Var a = (selObj. options [selObj. selectedIndex]. value );
For (I = 1; I <= a; I ++)
{
Document. getElementById (strOpt + I). style. display = "";
}
For (j = 10; j> a; j --)
{
Document. getElementById (strOpt + j). style. display = "none ";
}
}
// Read the database and show the hidden ID
// Usage
//
Program code
Function ListNumber_change (ListObj, ListStr)
{
Var a = ListObj;
For (I = 1; I <= a; I ++)
{
Document. getElementById (ListStr + I). style. display = "";
}
For (j = 10; j> a; j --)
{
Document. getElementById (ListStr + j). style. display = "none ";
}
}
// Iframe adaptive height
// Usage:
// OnLoad = "reSizeFrame ('iframe ID name ')"
Program code
Function reSizeFrame (frameID) {// frameID is your ifream name
Try {
Var oBody = eval (frameID + ". document. body ");
Var oFrame = document. all (frameID );
OFrame. style. height = oBody. scrollHeight + (oBody. offsetHeight-oBody. clientHeight );
}
Catch (e ){
Window. status = 'error: '+ e. number +'; '+ e. description;
}
}
Function checkPhone (getO)
{
Re =/^ ([\ d]) {2, 5}-([\ d]) {3, 14}/gi
Msg = "phone format error \ r \ n region number and phone number should be separated by"-", for example: 029-82303721"
Return regExpCheck (re, getO, msg)
}
// Verify the mobile phone number
Program code
Function checkMobile (getO)
{
Re =/^ (\ +? [0-9] {0, 3} 13 [0-9] {9}) $/gi
Msg = "Incorrect mobile phone format"
Return regExpCheck (re, getO, msg)
}
// Verify the verification code
Program code
Function checkVcode (getO)
{
Re =/^ (\ d {4}) $/gi
Msg = "Incorrect verification code format"
Return regExpCheck (re, getO, msg)
}
// Verify the number 1
Function checkNumber (getO)
{
Re =/^ \ d + $/gi
Msg = "format error. Enter 0 ~ 9 digit"
Return regExpCheck (re, getO, msg)
}
// Verify number 2
Function checkNumberText (get0, msg0)
{
Re =/^ \ d + $/gi
// Msg = msg0
Return regExpCheck (re, get0, msg0)
}
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.