本帖最后由 ddddsss123 于 2011-03-11 22:26:50 编辑

解决方案 »

  1.   

    <!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=gb2312" />
    <TITLE>百度一下,你就知道</TITLE>
    </head>
    <style type="text/css">
    .m{ border:1px solid #CCFF33; width:30px; float: right;
    text-align: center;}
    .z{border:1px dotted #00CCFF; width:50px;}
    .z li{height: 15px; width: 150px;border: 1px solid #993300;}
    ul{padding:0; margin:0; list-style:none; position:absolute;top:250px;left:300px;display: none;}
    .kk{border: thin solid #006699; width: 250px; height: 50px;
    position: relative; text-align: center;}
    .body{text-align: center;}
    </style>
    <body>
    <div class="kk" id="xx">x</div>
    <div class="kk">y</div>
      <ul class="z" id="sL">
      <li><a href="http://www.163.com">yy</a></li>
      <li><a href="http://www.163.com">yy</a></li>
      <li><a href="http://www.163.com">yy</a></li>
      <li><a href="http://www.163.com">yy</a></li>
      <li><a href="http://www.163.com">yy</a></li>
     </ul>
    </body>
    <script>
      
      window.onload=function(){
         document.getElementById('xx').onclick=function(){
     document.getElementById("sL").style.display = "block";
           }
        var li=document.getElementById("sL").getElementsByTagName("li");
    for(var i=0;i<li.length;i++)

          li[i].onmouseover=function(){
           this.style.background='red';
           }
       li[i].onmouseout=function(){
           this.style.background='white';
           }     }
      }
            //document.onclick = function(e){
            //var e = e||window.event,t = e.target||e.srcElement
            //if(t.innerHTML=='x') return
            //document.getElementById("sL").style.display = "none"
    </script>
    </html>这样可以吗。
    你的原代码写得有点乱,一个CSS能完成的,却写了2个(一个标签,一个CLASS)。没有必要写那么复杂,尽量简化比较好。
      

  2.   

    楼主的这个代码,是不是hao123上整下来的啊??
      

  3.   

    第4;打开隐藏块后回点X就隐藏UL了,能否取消。你都说取消了,为什么还要让其消失呢?你说点其他地方能让其收回指的是让UL层消失的意思吗?如果要让其消失,那也很简单!
     document.getElementById('页面上任何一个标签元素').onclick=function(){
     document.getElementById("sL").style.display = "none";
           }
    多加一条这个就能让其消失了!
    多加下面这一条,鼠标经过也能触发了!
      document.getElementById('xx').onmouseover=function(){
     document.getElementById("sL").style.display = "block";
           }
    第1鼠标经过已经无触发,你想通过鼠标经过来触发UL显示,那么
      

  4.   

    打开隐藏块后回点X就隐藏UL了,能否取消。
    什么意思? 是说显示ul后,只有点击页面其它地方才隐藏<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"> <!-- saved from url=(0021)http://www.HAO123.com/ --> <HTML><HEAD><TITLE>百度一下,你就知道</TITLE> 
    <META http-equiv=Content-Type content=text/html;charset=gb2312> </head>
    <style type="text/css"> .m{ border:1px solid #CCFF33; width:30px; float: right; text-align: center;}
     .z{border:1px dotted #00CCFF; width:50px; top: 48px; right: -169px; position:absolute; visibility: visible;}
      .z li{height: 15px; width: 150px;border: 1px solid #993300;}
       .z li a{display:block; height: 15px; width: 150px;}
       ul{padding:0; margin:0; list-style:none; float: right; display: none;} 
    .kk{border: thin solid #006699; width: 250px; height: 50px; position: relative; text-align: center;}
     .body{text-align: center;}</style>
      <body>
      <div class="kk">
     <div class="m" onMouseOver="show()">x</div>
      <ul class="z" id="sL" style="display: none;"> <li><a href="http://www.163.com">yy</a></li> <li><a href="http://www.163.com">yy</a></li> <li><a href="http://www.163.com">yy</a></li> <li><a href="http://www.163.com">yy</a></li> <li><a href="http://www.163.com">yy</a></li></ul> </div> <div class="kk"></div></body> 
    <script>
     function show() 
     { var tag = document.getElementById("sL") 
     if (tag.style.display=="none") { tag.style.display = "block" }} 
     document.onclick = function(e){ var e = e||window.event,t = e.target||e.srcElement;
      if(t.innerHTML=='x') return;
      document.getElementById("sL").style.display = "none"; } 
     window.onload=function(){
     var lis = document.getElementById("sL").getElementsByTagName("li");
     for(var i=0;i<lis.length;i++)
        { 
              lis[i].onmouseover=function(){
               this.style.backgroundColor='red';
               }
               lis[i].onmouseout=function(){
               this.style.backgroundColor='white';
               }     } };
     </script> </html>
      

  5.   

    都解决了,打开隐藏块后在经过X就隐藏UL了问题也修复了。