欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

最近项目写了一些js,水平有待提高

时间:2021-06-19 08:19:21|栏目:JavaScript代码|点击:
复制代码 代码如下:

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"){
//该操作为展开菜单,需要判断cookie中是否有该项
//1、有,删除
//2、无,不执行操作
changeshowmenu(obj);
for(var i = 0; i < len;i++){
dds[i].style.display = "";
}
}else{
//该操作为隐藏菜单,需要判断cookie中是否有该项:
//1、有,不执行操作
//2、无,则要在末尾添加进去
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) {//取得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){//添加cookie
var str = objName + "=" + objValue;
if(objHours > 0){//为0时不设定过期时间,浏览器关闭时cookie自动消失
var date = new Date();
var ms = objHours*3600*1000;
date.setTime(date.getTime() + ms);
str += "; expires=" + date.toGMTString();
}
document.cookie = str;
}

//根据一个以逗号分开的字符串,初始化菜单哪些需要隐藏
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("操作不可以恢复,确定当前操作吗?");
if(result){
return true;
}
}else{
alert("您还没有选中项");
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";
}
}
}

上一篇:为指定元素增加样式的js代码

栏    目:JavaScript代码

下一篇:兼容ie和firefox的鼠标经过(onmouseover和onmouseout)实现--简短版

本文标题:最近项目写了一些js,水平有待提高

本文地址:http://www.codeinn.net/misctech/144747.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有