本帖最后由 xiaoming00x 于 2011-11-24 17:17:35 编辑

解决方案 »

  1.   

    cell.onclick=function(){
    var evt=window.event,obj=evt.srcElement;
    alert(obj.innerHTML);
    }
      

  2.   


    楼上的有点看不太懂    function myOnmouseover(tableID){
            var table = document.getElementById(tableID);
             var rows = table.getElementsByTagName("tr");    
        
         for (i = 0; i < rows.length; i++) {
            var theadCells = rows[i].cells;        
            var cell = theadCells[0]; 
            var contractBWLayer = document.getElementById("Layer1");        cell.onmouseover = function ()
            {
                    //alert("hello");
                    mouseOver(contractBWLayer,event.screenX,event.screenY);
                    setTextContent(contractBWLayer,"hello");
            };
            cell.onmouseout = function(){
                displayDiv(contractBWLayer,"none");
            }        
         }我需要在这个方法中取到td的值...
      

  3.   

            cell.onmouseover = function ()
            {
                 mouseOver(contractBWLayer,event.screenX,event.screenY);
                 setTextContent(contractBWLayer,"hello" + this.innerHTML);
            };
    <script>
        
        
        function mouseOver(layerElment,x,y){
            locateDiv(layerElment,x,y);
            displayDiv(layerElment,"block")
        }
        
        function locateDiv(layerElment,x,y){
            layerElment.style.left = x;
            layerElment.style.top = y-100;
        }
        
        function displayDiv(layerElment,isDisplay){
            //alert(isDisplay);
            layerElment.style.display = isDisplay
        }
        
        function setTextContent(layerElment,textContent){
            layerElment.innerHTML = textContent;
        }
        
        function myOnmouseover(tableID){
            var table = document.getElementById(tableID);
            var rows = table.rows;    
        
         for (i = 0; i < rows.length; i++) {
            var theadCells = rows[i].cells;
            var cell = theadCells[0]; 
            var contractBWLayer = document.getElementById("Layer1");
            cell.onmouseover = function ()
            {
                 mouseOver(contractBWLayer,event.screenX,event.screenY);
                 setTextContent(contractBWLayer,"hello" + this.innerHTML);
            };
            cell.onmouseout = function(){
                displayDiv(contractBWLayer,"none");
            }        
         }
              
                        
        }
    </script><style type="text/css">
            <!--
            #Layer1 {
            
            position:absolute;
            left:0;
            top:0;
            width:100px;
            height:80px;        
            z-index:1;
            background-color: yellow;    
            display:none    
            }
            -->
    </style><div >
        <table class="table" id="statNodeAllList">
                    <tr>
                        <td >222</td>
                        <td >333</td>
                    </tr>
                    
                    <tr>
                        <td >333</td>
                        <td >333</td>
                    </tr>
    </div><div id="Layer1"></div><script type="text/javascript">
            myOnmouseover("statNodeAllList");
    </script>
      

  4.   


    cell.onmouseover = function ()
            {
                    //alert("hello");
                    mouseOver(contractBWLayer,event.screenX,event.screenY);
                    setTextContent(contractBWLayer,this.innerText);//this.innerText
            };this.innerText
    不过你这个封装有点简单复杂化了……
      

  5.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>PopUp-LIEHUO.NET</title>
    </head>
    <body>
    <script>
        
        
        function mouseOver(layerElment,x,y){
            locateDiv(layerElment,x,y);
            displayDiv(layerElment,"block")
        }
        
        function locateDiv(layerElment,x,y){
            layerElment.style.left = x;
            layerElment.style.top = y-100;
        }
        
        function displayDiv(layerElment,isDisplay){
            //alert(isDisplay);
            layerElment.style.display = isDisplay
        }
        
        function setTextContent(layerElment,textContent){
            layerElment.innerHTML = textContent;
        }
        
        function myOnmouseover(tableID){
            var table = document.getElementById(tableID);
             var rows = table.getElementsByTagName("tr");    
        
         for (i = 0; i < rows.length; i++) {
            var theadCells = rows[i].getElementsByTagName('td');        var contractBWLayer = document.getElementById("Layer1"); for(var j = 0; j < theadCells.length; j++){
    var cell = theadCells[j]
    cell.onmouseover = function ()
    {
    //alert("hello");
    mouseOver(contractBWLayer,event.screenX,event.screenY);
    setTextContent(contractBWLayer,"hello");
    };
    cell.onmouseout = function(){
    displayDiv(contractBWLayer,"none");
    }  
    }
         }            
                        
        }
    </script><style type="text/css">
            <!--
            #Layer1 {
            
            position:absolute;
            left:0;
            top:0;
            width:100px;
            height:80px;        
            z-index:1;
            background-color: yellow;    
            display:none    
            }
            -->
    </style><div >
        <table class="table" id="statNodeAllList">
                    <tr>
                        <td >222</td>
                        <td >333</td>
                    </tr>
                    
                    <tr>
                        <td >333</td>
                        <td >333</td>
                    </tr>
                    </table>
    </div><div id="Layer1"></div><script type="text/javascript">
            myOnmouseover("statNodeAllList");
    </script>
    </body>
    </html>