IE5.5+能用<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)
if(obj.tagName=="TD")obj.fireEvent("onmouseout"); 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)
if(obj.tagName=="TD")obj.fireEvent("onmouseover");
}
}function window.onload(){
document.onmousedown = doMouseDown;
document.onmousemove = doMouseMove;
document.onmouseup = new Function("curElement =null")
}
//-->
</SCRIPT>
<style type="text/css">
<!--
.tdChangeColor {behavior:url(tdChangeColor.htc)}
-->
</style>
</HEAD><BODY BGCOLOR="#FFFFFF">
<div id="oframe" style="position:absolute;left:10;top:30;width:40;background-color:#cccccc">aaaaaaa</div><table width="300" border="1" cellspacing="3" cellpadding="3">
  <tr>
    <td class="tdChangeColor">&nbsp;</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>

解决方案 »

  1.   

    可惜我浏览器是ie5 谢谢秋水弟弟 ^w^ akane再看看
      

  2.   

    如果不是IE5.5+,那就将tdChangeColor的代码提出来<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)
    if(obj.tagName=="TD")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)
    if(obj.tagName=="TD")obj.runtimeStyle.backgroundColor='#ff0000'; }
    }function window.onload(){
    document.onmousedown = doMouseDown;
    document.onmousemove = doMouseMove;
    document.onmouseup = new Function("curElement =null")
    }
    //-->
    </SCRIPT>
    <style type="text/css">
    <!--
    .tdChangeColor {behavior:url(tdChangeColor.htc)}
    -->
    </style>
    </HEAD><BODY BGCOLOR="#FFFFFF">
    <div id="oframe" style="position:absolute;left:10;top:30;width:40;background-color:#cccccc">aaaaaaa</div><table width="300" border="1" cellspacing="3" cellpadding="3">
      <tr>
        <td class="tdChangeColor">&nbsp;</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>
      

  3.   

    我还以为是这个5.0下不能创建呢
    document.elementFromPoint(curElement.style.pixelLeft,curElement.style.pixelTop)
    原来是htc不能响应那样子fire的事件?^o^ 好用了 加分