点击空白地方DIV消失 为什么IE下没有效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.div{
width:200px;
height:200px;
background:#CCC;
}
</style>
</head>
<body>
<div class="div" name="sy_xiand" style="display:block;"></div>
</body>
<script type="text/javascript">
var xdivs=document.getElementsByName('sy_xiand')
document.onclick=function()
{
for(var i=0;i<xdivs.length;i++) xdivs[i].style.display='none';
}
</script>
</html>
------解决方案--------------------
要操作多个div,可以改用class
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.div{
width:200px;
height:200px;
background:#CCC;
}
</style>
</head>
<body>
<div class="div sy_xiand" style="display:block;"></div>
</body>
<script type="text/javascript">
var xdivs=document.querySelectorAll(".sy_xiand");
document.onclick=function()
{
for(var i=0;i<xdivs.length;i++) xdivs[i].style.display='none';
}
</script>
</html>