大家谁能给我翻译下这段js,我实在搞不懂是什么意思(模仿QQ菜单,我从网上找的)!!!!!!!!!
<html>
<head>
<style type= "text/css ">
.menutitle{
cursor:pointer;
margin-bottom: 5px;
background-color:#ECECFF;
color:#000000;
width:140px;
padding:2px;
text-align:center;
font-weight:bold;
/*/*/border:1px solid #000000;/* */
}
.submenu{
margin-bottom: 0.5em;
}
</style>
<script type= "text/javascript ">
/***********************************************
我对js基本不懂,谢谢高手给讲解一下,麻烦了!!!
***********************************************/
//这句话是在做什么呢,是在判断什么呢
if (document.getElementById){
document.write( ' <style type= "text/css "> \n ')
document.write( '.submenu{display: none;}\n ')
document.write( ' </style> \n ')
}
function SwitchMenu(obj){
if(document.getElementById){
var el = document.getElementById(obj);
var ar = document.getElementById( "masterdiv ").getElementsByTagName( "span "); //这个ar代表什么
//下面这些js是在判断什么,我一点也读不懂!!!!!!!
if(el.style.display != "block "){
for (var i=0; i <ar.length; i++){//ar.length是什么,他是代表span长度,是吗??
if (ar[i].className== "submenu ")
ar[i].style.display = "none ";//这个代表什么不可见了
}
el.style.display = "block "; //这个代表 "锁定 "????
}else{
el.style.display = "none ";//这好象不代表对象不可见??????
}
}
}
</script>
</head>
<body>
<div id= "masterdiv ">
<div class= "menutitle " onclick= "SwitchMenu( 'sub1 ') "> 网页特效 </div>
<span class= "submenu " id= "sub1 "> - <a href= "# "> 图形图象 </a> <br>
- <a href= "# "> 鼠标事件 </a> <br>
- <a href= "# "> 时间日期 </a> <br>
- <a href= "# "> 导航菜单 </a> </span>
<div class= "menutitle " onclick= "SwitchMenu( 'sub2 ') "> 插件中心 </div>
<span class= "submenu " id= "sub2 "> - <a href= "# "> DW插件 </a> <br>
- <a href= "# "> FW插件 </a> <br>
- <a href= "# "> ps滤镜 </a> </span>
<div class= "menutitle " onclick= "SwitchMenu( 'sub3 ') "> 网络学院 </div>
<span class= "submenu " id= "sub3 "> - <a href= "# "> 网页制作 </a> <br>
</span>
<div class= "menutitle " onclick= "SwitchMenu( 'sub4 ') "