<SCRIPT language="javascript"></SCRIPT>
<BODY>
<INPUT id="txt1" onMouseDown="document.all.div1.innerHTML = event.srcElement.id" 
                 onMouseUp="document.all.div1.innerHTML = event.srcElement.id"><br><br>
<INPUT id="txt2" onMouseDown="document.all.div1.innerHTML = event.srcElement.id" 
                 onMouseUp="document.all.div1.innerHTML = event.srcElement.id"><br><br>
<DIV id="div1" style="border:1px solid black; width:100px; height:100px"></DIV>
</BODY>

解决方案 »

  1.   

    譬如:<td>a</td>             <td>b</td>
    我想在鼠标onmousedowu的时候获得a
    然后移动鼠标到b上面
    在鼠标onmouseup的时候获得b的对象
    我用document.activeElement跟event.srcElement来获取,可是onmousedown,onmouseup,当第一次按下鼠标不能及时获得onmousedown的对象 但能获得onmouseup的对象
    但是第二次down的时候,获得第一次down的对象
    这一段就是我写的测试代码
    <HTML xmlns:v>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE>test</TITLE>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    //-->
    </script>
    <style type="text/css">
    <!--
    .style13 {font-weight: bold;
    font-family: "Times New Roman", Times, serif;
    font-size: 13px;
    }
    .style18 {font-size: 14px; font-style: normal; font-weight: bold; font-variant: normal; text-transform: capitalize; text-decoration: none; }
    .style2 {font-size: 15px;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    }
    .style6 {font-size: 13px;
    font-style: italic;
    font-weight: bold;
    font-family: Arial, Helvetica, sans-serif;
    }
    .style7 {font-family: Arial, Helvetica, sans-serif; font-size: 14px;}
    .unnamed1 { font-family: "默认字体";
    font-size: 13px;
    font-style: normal;
    font-variant: normal;
    }
    .link1 {font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-style: normal;
    font-weight: bold;
    color: #FFFFFF;
    text-decoration: none;
    text-transform: capitalize;
    }
    -->
    </style>
    <STYLE>
    v\:*{behavior:url(#default#VML);}   /*声明V为VML变量*/
    a{text-Decoration:none;color:white}
    a:hover{text-Decoration:underline;color:yellow;}
    td{font-size:12px;color:white}
    .bon1{border-bottom:1 solid eeeeee;border-right:1 solid eeeeee;border-left:1 solid gray;border-top:1 solid gray;background-color:#619CE7;color:yellow;width:54}
    .bon2{border-bottom:1 solid gray;border-right:1 solid gray;border-left:1 solid eeeeee;border-top:1 solid eeeeee;background-color:#619CE7;color:white;width:54}
    </STYLE>
    </HEAD>
    <BODY oncontextmenu="return false"  style="MARGIN: 1px; CURSOR: default" vlink=#3732cd link='#3732cd' onselectstart='if(event.srcElement.tagName!="TEXTAREA"&amp;&amp;event.srcElement.tagName!="INPUT")return false'>
    <v:Line style="DISPLAY: none; Z-INDEX: 2000; POSITION: absolute" id='line1' from = "0,0" to = "0,0"><!--钢笔可视化-->
    <v:stroke dashstyle = "shortDash"/></v:Line><div style="BORDER-RIGHT: gray 1px solid; BORDER-TOP: gray 1px solid; BORDER-LEFT: gray 1px solid; WIDTH: 450px; COLOR: black; BORDER-BOTTOM: gray 1px solid; HEIGHT: 50%; BACKGROUND-COLOR: white" id=div1 ><table onmousemove=mouseMove() onmousedown=down() onmouseup=up()   bgcolor=dimgray width="800"  height="200" border="0" cellpadding="0" cellspacing="0">
    <tr><td style="CURSOR: crosshair" id="aa" value="aaaaa">aaaaa</td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td value="aa" id="a" >ggggg</td></tr>
    <tr><td style="CURSOR: crosshair"  id="bb" value="bbbbb">bbbbb</td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td value="ee" id="e">eeeee</td></tr>
    <tr><td style="CURSOR: crosshair"  id="cc" value="ccccc">ccccc</td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td value="dd" id="d">ddddd</td></tr>
    <tr><td style="CURSOR: crosshair"  id="dd" value="ddddd">ddddd</td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td value="cc" id="c">ccccc</td></tr>
    <tr><td style="CURSOR: crosshair"  id="ee" value="eeeee">eeeee</td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td  value="bb" id="b">bbbbb</td></tr>
    <tr><td style="CURSOR: crosshair"  id="gg" value="ggggg">ggggg</td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td value="aa" id="a">aaaaa</td></tr></table>
    <table>
      <DIV></DIV></table>
    </div>
    </v:stroke>
    </BODY>
    </HTML>
    <SCRIPT LANGUAGE=javascript>
    var d;
    var u;
    var obj;
    var text;
    var tempx,tempy;
    var color1='#000000',color2='#000000',size1=1  //定义缺剩的画笔颜色及画笔填充颜色和笔边粗度
    var xx=0,yy=0,zz=1000  //定义缺剩的X及Y坐标var lineLeft;
    var lineTop;
    function down(){

    d = document.activeElement.id;
    /*
    div1.setCapture();
    xx = event.x; 
    yy = event.y;
    zz+=1;
    line1.strokecolor=color1;line1.strokeweight=size1;//定义当前的钢笔参数
    line1.style.left=event.x;line1.style.top=event.y;
    line1.to="0,0";
    line1.style.display="";
    lineLeft = line1.style.left;
    lineTop = line1.style.top;
    */
    }function mouseMove(){
    //tempx = event.x;
    //tempy = event.y;
    //line1.to=(tempx-xx)+","+(tempy-yy);

    }function up(){
    //alert(event.srcElement.tagName);
    u = event.srcElement.value;
    alert(d)
    alert(u)

    //document.releaseCapture();
    //tempx=event.x;tempy=event.y;
    //div1.appendChild(document.createElement("<v:line style='position:absolute;z-index:"+zz+";left:"+xx+";top:"+yy+";' to='"+(event.x-xx)+","+(event.y-yy)+"' strokecolor='"+color1+"' strokeweight='"+size1+"'/>"))
    //line1.style.display="none";
    //u = null; 
    //d = null;

    }
      

  2.   

    DownObject=event.srcElement;
    UpObject=document.all.ObjectID;
      

  3.   

    注意document.releaseCapture();和DivID.setCapture();的应用就可以了.
      

  4.   

    我想获得的效果是就行两两连线,我已做好的页面是用固定位置来判断的,太死板了
    我想改用onomousedown,onmouseup获得不同对象来判断,可是没找到能让鼠标按下跟松开时获得不同对象的方法,请大家帮帮忙
      

  5.   

    对 gjd111686(数字金刚) ( ) 信誉:99 
    大虾你能不能说清楚点
      

  6.   

    各位兄弟,我onmousedown的时候取得一个对象,然后移动对象(譬如一个div,鼠标拖动一段字,或者图片),移到指定的对象上面,做onmouseup动作,放在移到的指定对象上面不动
    onmousedown的时候肯定可以获得对象,可是当onmouseup的时候,我怎么获得当前鼠标下对应的对象。
    我现在能做到移动时不拖动down时获得的对象,那么up时就能得到当前鼠标下的对象
    可是移动时拖动对象,那么就无法取得任何对象了。因为鼠标下的对象是移动的那个对象,怎么能透过移动的div,获得鼠标当前对象
    请大家帮帮忙
    我本来是通过固定的定位来做的,可是固定定位效果不好,不同的显示器,位置就跑掉了。而且太过死板