Recently, some javascript code has been written in the project, and the level needs to be improved _ javascript skills

Source: Internet
Author: User
Tags openid
Recently, some js functions have been written in the project, and the level needs to be improved. The Code is as follows:


Function ResumeError (){
Return true;
}
Window. onerror = ResumeError;

Function showdd (obj ){
Var dds = document. getElementById (obj). getElementsByTagName ("dd ");
Var len = dds. length;
If (dds [0]. style. display = "none "){
// This operation is an expanded menu. You need to determine whether this option exists in the cookie.
// 1. Yes, delete
// 2. None. do not perform the operation
Changeshowmenu (obj );
For (var I = 0; I <len; I ++ ){
Dds [I]. style. display = "";
}
} Else {
// This operation is a hidden menu. You need to determine whether this option exists in the cookie:
// 1. Yes. No operation is performed.
// 2. If no, add it to the end
Changehidemenu (obj );
For (var I = 0; I <len; I ++ ){
Dds [I]. style. display = "none ";
}
}
}

Function changeshowmenu (obj ){
Var temp = getcookie ("openid ");
If (temp. indexOf (obj )! = "-1 "){
Temp = temp. replace (obj + ",","")
Addcookie ("openid", temp, 24 );
}
}

Function changehidemenu (obj ){
Var temp = getcookie ("openid ");
If (temp. indexOf (obj) = "-1 "){
Addcookie ("openid", temp + obj + ",", 24 );
}
}


Function getcookie (sName) {// get cookie
Var aCookie = document. cookie. split (";");
For (var j = 0; j <aCookie. length; j ++ ){
Var aCrumb = aCookie [j]. split ("= ");
If (sName = aCrumb [0])
Return aCrumb [1];
}
Return null;
}

Function addcookie (objName, objValue, objHours) {// Add cookie
Var str = objName + "=" + objValue;
If (objHours> 0) {// when the value is 0, no expiration time is set. When the browser is disabled, the cookie disappears automatically.
Var date = new Date ();
Var MS = objHours x 3600*1000;
Date. setTime (date. getTime () + MS );
Str + = "; expires =" + date. toGMTString ();
}
Document. cookie = str;
}

// Based on a string separated by commas (,), which of the initialization menus need to be hidden?
Function initmenu (obj ){
Var arrmenu = obj. split (",");
For (var I = 0; I <arrmenu. length; I ++ ){
Var dds = document. getElementById (arrmenu [I]). getElementsByTagName ("dd ");
For (var j = 0; j <dds. length; j ++ ){
Dds [j]. style. display = "none ";
}
}
}

Function $ (obj ){
Return document. getElementById (obj );
}

Function delIt (){
Var cbxBool = 0;
For (var I = 0; I <cbxArray. length; I ++ ){
Var obj = $ (cbxArray [I]);
If (obj. checked = true ){
CbxBool = 1;
Break;
}
}

If (cbxBool = 1 ){
Var result = confirm ("the operation cannot be recovered. Are you sure you want to perform the current operation? ");
If (result ){
Return true;
}
} Else {
Alert ("You have not selected ");
Return false;
}
Return false;

}
Window. onload = function (){
Var lendl = document. getElementById ("globalLeft"). getElementsByTagName ("dl"). length;
If (getcookie ("openid") = null ){
Addcookie ("openid", "dl_c, dl_d, dl_e, dl_f, dl_g, dl_h, dl_ I, dl_j,", 24 );
}
Initmenu (getcookie ("openid "));



Var otable = document. getElementById ("table ");
Var trs = otable. getElementsByTagName ("tr ");
For (var I = 0; I <trs. length; I ++ ){
Trs [I]. onmouseover = function (){
This. style. backgroundColor = "# F7F7F7 ";
}
Trs [I]. onmouseout = function (){
This. style. backgroundColor = "# FFFFFF ";
}
}
}

Related Article

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.