注:火狐和ie获取display的方法不同,用前先判断,要不不兼容
var
currentstyle
=
function(e){
return
e.currentstyle
||
document.defaultview.getcomputedstyle(e,
null)
}
if(currentstyle(document.getelementbyid(id))['display']=='none'){
document.getelementbyid(divname).style.display
=
"block"
}else{
document.getelementbyid(divname).style.display
=
"none"
}
可能是事件用错了:用onmouseout子菜单隐藏:document.getElementById("子项ID").style.display="none"
加一起就是onmouseout="document.getElementById('子项ID').style.display='none'"
需要准备的材料分别有:电脑、html编辑器、浏览器。
1、首先,打开html编辑器,新建html文件,例如:index.html,填写问题基础代码。
2、在index.html中的<script>标签,输入js代码:
function fun() {
if ($('#ChildMenu1').css('display') == 'none') {
$('#ChildMenu1').css('display', 'block')
} else {
$('#ChildMenu1').css('display', 'none')
}
}
3、浏览器运行index.html页面,此时点击按钮即可让菜单显示或隐藏。