Operation cookie by javascript: cookie
Function getcookie (c_name)
{
If (document. Cookie. length> 0)
{
C_start = Document. Cookie. indexof (c_name + "= ");
If (c_start! =-1)
{
C_start = c_start + c_name.length + 1;
C_end = Document. Cookie. indexof (";", c_start );
If (c_end =-1)
C_end = Document. Cookie. length;
Return decodeuricomponent (document. Cookie. substring (c_start, c_end ));
}
}
Return NULL;
}
Function setcookie (c_name, value, expiredays)
{
VaR exdate = new date ();
Exdate. setdate (exdate. getdate () + expiredays );
Document. Cookie = c_name + "=" + escape (value) + (expiredays = NULL )? "": "; Expires =" + exdate );
}
Getcookie, setcookie, delcookie: setcookie, getcookie, delcookie
Function setcookie (name, value)
{
VaR days = 30; // This cookie will be saved for 30 days
VaR exp = new date (); // new date ("December 31,999 8 ");
Exp. settime (exp. gettime () + days x 24x60*60*1000 );
Document. Cookie = Name + "=" + escape (value) + "; expires =" + exp. togmtstring ();
}
Function getcookie (name)
{
VaR arr = Document. Cookie. Match (New Regexp ("(^ |)" + name + "= ([^;] *) (; | $ )"));
If (Arr! = NULL) return Unescape (ARR [2]); return NULL;
}
Function delcookie (name)
{
VaR exp = new date ();
Exp. settime (exp. gettime ()-1 );
VaR cval = getcookie (name );
If (cval! = NULL) document. Cookie = Name + "=" + cval + "; expires =" + exp. togmtstring ();
}
Getelementsbyclassname: Function getelementsbyclassname (searchclass, domnode, tagname ){
Alert (searchclass );
If (domnode = NULL) domnode = document;
If (tagname = NULL) tagname = '*';
VaR El = new array ();
VaR tags = domnode. getelementsbytagname (tagname );
VaR TCL = "" + searchclass + "";
For (I = 0, j = 0; I <tags. length; I ++ ){
VaR test = "" + tags [I]. classname + "";
If (test. indexof (TCL )! =-1)
El [J ++] = tags [I];
}
Alert (EL );
Return El;
}
Event: VaR eventutil = new object;
// Otarget: Target; seventtype: event name; funname: name of the function triggered by the event;
Eventutil. addevent = function (otarget, seventtype, funname ){
If (otarget. addeventlistener) {// For Dom;
Otarget. addeventlistener (seventtype, funname, false );
} Else if (otarget. attachevent ){
Otarget. attachevent ("On" + seventtype, funname );
} Else {
Otarget ["on" + seventtype] = funname;
}
};
Eventutil. removeevent = function (otarget, seventtype, funname ){
If (otarget. removeeventlistener) {// For Dom;
Otarget. removeeventlistener (seventtype, funname, false );
} Else if (otarget. detachevent ){
Otarget. detachevent ("On" + seventtype, funname );
} Else {
Otarget ["on" + seventtype] = NULL;
}
};
It is more practical and does not need a lot of useless code.