如果table里没有其他的东东 可以用 document.elementFromPoint()找到目标,但是如果table里有很多东东(而且不能预知table可能会有什么,会有几层元素) 就完全没办法了 -_-;;怎么能够有 不管最外层的table里有多少东西,都可以让他背景色变红呢 一个通用的处理方法呢

解决方案 »

  1.   

    你最好能说得再清楚一些,你想实现什么?比如,可以屏弊掉拖拽事件:ondragstart='return false'
      

  2.   

    你最好能说得再清楚一些,你想实现什么?比如,可以屏弊掉拖拽事件:ondragstart='return false'
      

  3.   

    期望拖动一物体到 一个table "A" 上空(A里填充有其它元素b,c,而且b,c不一定是什么元素)期望A底色变化
      

  4.   

    设置Capture,然后把table放到鼠标后(不要档住鼠标)
    那么document.elementFromPoint()能用。
      

  5.   

    看来只有判断位置了:-(-----------------------------------------------
    <table width=400 height=300 border=1>
      <tr>
        <td align=left valign=top>
          <div style="position:absolute;">
            <div style="position:absolute;width:80;height:60;background-color:#FF0000;left:500px;top:30px;cursor:default;"
            onmousedown="setCapture();X=event.x;Y=event.y;myLeft=this.style.pixelLeft;myTop=this.style.pixelTop;"
            onmouseup="releaseCapture();"
            onmousemove="if(event.button==1){this.style.pixelLeft=myLeft+(event.x-X);this.style.pixelTop=myTop+(event.y-Y);
            if(this.style.pixelLeft>=0&&this.style.pixelLeft<=400&&this.style.pixelTop>=0&&this.style.pixelTop<=300)
            parentNode.parentNode.parentNode.bgColor='#0000FF';else parentNode.parentNode.parentNode.bgColor='#FFFFFF';}">
            <br>&nbsp;Drag me!</div>
          </div>
          asdfasdfsadfsadf<br><br><img src=asdfasdf width=300 height=120>
        </td>
      </tr>
    </table>
      

  6.   

    我是在IE5下调的代码。建议你同时看看IE5.5和IE6的效果吧,我发现在IE6中对负值定位支持的不太好。如果表格在中间,就必须考虑pixelLeft和pixelTop是负的情况,这在IE5中没什么问题,在IE6中就不太好说了。
      

  7.   

    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var curElement,wx,wy,cx,cy,sx,sy,px,py;
    var oeventX,oeventY;
    //=============================================
    function doMouseDown() 
    {
    if ((event.button==1) && (event.srcElement.id=="oframe"))curElement = event.srcElement;oeventX1=event.clientX;
    oeventY1=event.clientY;
    }function doMouseMove(){
    if ((event.button==1) && (curElement!=null)){ 
    // 定位图层
    newleft= oframe.offsetLeft+(event.clientX-oeventX1);var obj=document.elementFromPoint(curElement.style.pixelLeft,curElement.style.pixelTop)
    while(!(obj.tagName=="TD"&&obj.className=='tdChangeColor')&&obj.parentElement){obj=obj.parentElement}
    if(obj.tagName=="TD"&&obj.className=='tdChangeColor')obj.runtimeStyle.backgroundColor=''; if (newleft<0){newleft=0;}//自动调整层横坐标位置
    curElement.style.pixelLeft=newleft;
    oeventX1=event.clientX; newtop=oframe.offsetTop+(event.clientY-oeventY1);
    if (newtop<0){newtop=0;}//自动调整层纵坐标位置
    curElement.style.pixelTop= newtop;
    oeventY1=event.clientY;
    event.returnValue = false;
    event.cancelBubble = true;var obj=document.elementFromPoint(curElement.style.pixelLeft,curElement.style.pixelTop)
    while(!(obj.tagName=="TD"&&obj.className=='tdChangeColor')&&obj.parentElement){obj=obj.parentElement}
    if(obj.tagName=="TD"&&obj.className=='tdChangeColor')obj.runtimeStyle.backgroundColor='#ff0000'; }
    }function window.onload(){
    document.onmousedown = doMouseDown;
    document.onmousemove = doMouseMove;
    document.onmouseup = new Function("curElement =null")
    }
    //-->
    </SCRIPT>
    </HEAD><BODY BGCOLOR="#FFFFFF">
    <div id="oframe" style="position:absolute;left:10;top:30;width:40;background-color:#cccccc">
    aaaaaaa<TABLE>
    <TR>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    </TR>
    <TR>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    </TR>
    <TR>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    </TR>
    <TR>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    <TD>&copy;</TD>
    </TR>
    </TABLE></div><table width="300" border="1" cellspacing="3" cellpadding="3">
      <tr>
        <td class="tdChangeColor">
    <TABLE bgcolor="#00ffff">
    <TR>
    <TD>111</TD>
    <TD>11111</TD>
    </TR>
    </TABLE>
    </td>
        <td class="tdChangeColor" >&nbsp;</td>
        <td class="tdChangeColor">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td class="tdChangeColor">&nbsp;</td>
      </tr>
      <tr>
        <td class="tdChangeColor">&nbsp;</td>
        <td class="tdChangeColor">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></BODY>
    </HTML></noscript>
    </SCRIPT>
      

  8.   

    我在 ie6 下看也正常.......
    ================================================================
    俺是"老"菜鸟一只, 请各位高手多指教!
    ------ 好好学习, 天天上网! --------
    →→→→→→→→→→→→→→→→→→→→
    http://www.boy.net.cn/home0/goldenlove 
    ←←←←←←←←←←←←←←←←←←←←
    多谢 CSDN 助手帮我自动加入签名. 
    www.chinaok.net
    ================================================================
      

  9.   

    谢谢zz315(钟钟)  :)不过你的方法不适合akane要做的东最后akane自己解决了 
    解决的思路和 ncs2002(还记得那个花落如雨的夜晚吗)的一样