求理解下这段js代码,同求相关书籍。 是实现图片切换的http://www.shyp.gov.cn/zjyp/ 知识杨浦那部门的
<!--vardivs=["ww","xx","dd","bb","cc","kk","hh"];functionMM_changeShowImg(currObj){va...
<!--
var divs= ["ww","xx","dd","bb","cc","kk","hh"];
function MM_changeShowImg(currObj){
var sId= currObj.id;
var currDisplay = document.getElementById(sId+"_c").style.display;
if(currDisplay!="none"){return;}
for(var i=0; i<divs.length;i++){
var bDis = document.getElementById(divs[i]+"_c").style.display;
var imgSrc = document.getElementById(divs[i]).src;
var imgName=imgSrc.split("/");
var src=imgName[imgName.length-1];
var tar=src.replace("c","_c");
var tar1=src.replace("_c","c");
if(divs[i]==sId){
document.getElementById(divs[i]).src = imgSrc.replace(src,tar);
document.getElementById(divs[i]+"_c").style.display="block";
}else if(bDis!="none"){
document.getElementById(divs[i]+"_c").style.display="none";
document.getElementById(divs[i]).src = imgSrc.replace(src,tar1);
}
}
}
//--> 展开
var divs= ["ww","xx","dd","bb","cc","kk","hh"];
function MM_changeShowImg(currObj){
var sId= currObj.id;
var currDisplay = document.getElementById(sId+"_c").style.display;
if(currDisplay!="none"){return;}
for(var i=0; i<divs.length;i++){
var bDis = document.getElementById(divs[i]+"_c").style.display;
var imgSrc = document.getElementById(divs[i]).src;
var imgName=imgSrc.split("/");
var src=imgName[imgName.length-1];
var tar=src.replace("c","_c");
var tar1=src.replace("_c","c");
if(divs[i]==sId){
document.getElementById(divs[i]).src = imgSrc.replace(src,tar);
document.getElementById(divs[i]+"_c").style.display="block";
}else if(bDis!="none"){
document.getElementById(divs[i]+"_c").style.display="none";
document.getElementById(divs[i]).src = imgSrc.replace(src,tar1);
}
}
}
//--> 展开
展开全部
var divs = ["ww", "xx", "dd", "bb", "cc", "kk", "hh"]; //图片ID 集合
function MM_changeShowImg(currObj) { //参数 currObj 为 img 对象(选项卡)
var sId = currObj.id; //取id
//获取与图片一一对应的某个标签是否可见(ID 规则 = 图片ID + '_c')
var currDisplay = document.getElementById(sId + "_c").style.display;
//如果该标签不隐藏,即显示状态,则不作任何操作
if (currDisplay != "none") {
return;
}
for (var i = 0; i < divs.length; i++) { //遍历所有图片(选项卡)
//该图片所对应的标签是否可见(选项卡下的内容页)
var bDis = document.getElementById(divs[i] + "_c").style.display;
//以下5行为选项卡图片切换的 文件名自定义规则
var imgSrc = document.getElementById(divs[i]).src; //当前选项卡图片路径
var imgName = imgSrc.split("/"); //拆分为目录数组
var src = imgName[imgName.length - 1]; //数组最后一个为图片文件名
var tar = src.replace("c", "_c"); //焦点规则
var tar1 = src.replace("_c", "c"); //非焦点规则
if (divs[i] == sId) { //判断是否是当前选中的项
//替换图片路径为焦点图片
document.getElementById(divs[i]).src = imgSrc.replace(src, tar);
//显示内容页
document.getElementById(divs[i] + "_c").style.display = "block";
} else if (bDis != "none") { //判断是否是之前显示的项
//隐藏内容页
document.getElementById(divs[i] + "_c").style.display = "none";
//替换图片路径为非焦点图片
document.getElementById(divs[i]).src = imgSrc.replace(src, tar1);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询