我想在固定大小的div块里放个文字连接,如何在光标移到文字连接上时,这个div块背景色变色啊,以下是我看的人家的例子是用table做的,那是可以的,但我改成div就不可以了,为何,应该怎么实现这个效果啊
<script type="text/javascript">    
      function mOvr(src,clrOver) { if (!src.contains(event.fromElement)){ src.bgColor = clrOver; }}function mOut(src,clrIn){ if (!src.contains(event.toElement)) { src.style.cursor = 'hand'; src.bgColor = clrIn; }} function mClk(src) { if(event.srcElement.tagName=='TD'){src.children.tags('A')[0].click();} }
      function pageLoad() {
      }    
    </script><div class="leiblock" onmousemove="mOvr(this,'#000000');" onclick="mClk(this);" onmouseout="mOut(this,'#ffffff');"><a href= "../Default.aspx">详情点击</a></div>

解决方案 »

  1.   

     <div class="leiblock" onmouseover="this.style.backgroundColor='#CCC'" onmouseout="this.style.backgroundColor=''">
                    <a href="../Default.aspx">详情点击 </a>
                </div>
      

  2.   

    <script type="text/javascript">    
    function mOvr(src,clrOver)
    {
      if (!src.contains(event.fromElement))
      {
        src.style.background = clrOver;
      }
    }function mOut(src,clrIn)
    {
      if (!src.contains(event.toElement))
      {
        src.style.cursor = 'hand';
        src.style.background = clrIn;
      }
    }function pageLoad()
    {
    }
    </script> <div class="leiblock" onmousemove="mOvr(this,'#000000');" onmouseout="mOut(this,'#ffffff');" style="width: 300px"><a href="../Default.aspx">详情点击 </a></div>
      

  3.   

    老兄,你请教也把代码写好啊,那种代码光读懂,都要费好长时间呢.
    我写的:function changeColor(){
            var idName=document.getElementByClassName("id");
             leiblock.onmouseover=function(){
                  idName.style.backgroundColor="#CCCCCC";
                  }
             idName.onmouseout=function(){
                  idName.style.backgroundColor="#FFFFFF";
                  }
            }
    window.onload=function(){
           changeColor();
          }给所要变色的div设置一个id,将上面写入一个js 文件,在页面中引入.