<!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>

解决方案 »

  1.   

    <div class="div" id="sy_xiand" style="display:block;"></div>
    将 name改成id
      

  2.   

    getElementsByName
    这个东西的支持度不高,尽量少用。
      

  3.   

    换成window.onclick=function()
    {
        for(var i=0;i<xdivs.length;i++)  xdivs[i].style.display='none';
    }
    试一下
    IE10正常
      

  4.   

    var xdivs=document.getElementsByName('sy_xiand')
    检查 所有浏览器 是什么结果
      

  5.   

    请问下 那要用什么 才能实现  点击空白的地方多个div消失
      

  6.   

    如果 换成id 怎么才能实现点击空白的地方多个div消失呢
      

  7.   

    ie中div不支持name属性name属性只有以下元素才支持
    A, APPLET, attribute, BUTTON, EMBED, FORM, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, LINK, MAP, OBJECT, RT, RUBY, SELECT, TEXTAREA
      

  8.   

    如果 换成id 怎么才能实现点击空白的地方多个div消失呢
    要操作多个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>
      

  9.   

    如果 换成id 怎么才能实现点击空白的地方多个div消失呢
    要操作多个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>

    谢谢了  不过这个方法在ie7以下 还是没有效果  不过刚刚用jquery解决了  还是谢谢你了
      

  10.   

    getElementsByName在IE下面获取表单元素比较准
      

  11.   

    获取DIV 或者Span应该都不行