第一步:把如下代码加入<body>区域中
<SCRIPT LANGUAGE="JavaScript">
var newtop=0
var newleft=0
if (navigator.appName == "Netscape") {
layerStyleRef="layer.";
layerRef="document.layers";
styleSwitch="";
}
else
{
layerStyleRef="layer.style.";
layerRef="document.all";
styleSwitch=".style";
} function doMouseMove() { layerName = 'iit' eval('var curElement='+layerRef+'["'+layerName+'"]')
eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"')
eval('curElement'+styleSwitch+'.visibility="visible"')
eval('newleft=document.body.clientWidth-curElement'+styleSwitch+'.pixelWidth')
eval('newtop=document.body.clientHeight-curElement'+styleSwitch+'.pixelHeight')
eval('height=curElement'+styleSwitch+'.height')
eval('width=curElement'+styleSwitch+'.width')
width=parseInt(width)
height=parseInt(height)
if (event.clientX > (document.body.clientWidth - 5 - width))
{
newleft=document.body.clientWidth + document.body.scrollLeft - 5 - width
}
else
{
newleft=document.body.scrollLeft + event.clientX
}
eval('curElement'+styleSwitch+'.pixelLeft=newleft') if (event.clientY > (document.body.clientHeight - 5 - height))
{
newtop=document.body.clientHeight + document.body.scrollTop - 5 - height
}
else
{
newtop=document.body.scrollTop + event.clientY
}
eval('curElement'+styleSwitch+'.pixelTop=newtop')
} document.onmousemove = doMouseMove;</SCRIPT>
第二步:把如下代码加入<body>区域中
<script language="javascript">
if (navigator.appName == "Netscape") { }
else
{
document.write('<div ID=OuterDiv>')
document.write('<img ID=iit src="image1.gif" STYLE="position:absolute;TOP:0pt;LEFT:0pt;width=103;height=28;Z-INDEX:2;visibility:hidden;">')
document.write('</div>')
}
</script>

解决方案 »

  1.   

    <div onmousedown=setCapture() onmouseup=releasCapture() onmousemove="this.style.left=event.clientX;this.style.top=event.clientY" style="position:absolute">adgfasd</div>
      

  2.   

    改成
    document.onmousedown = doMouseMove;
      

  3.   

    不行的,我想作到如果按下鼠标,则层随鼠标移动,放开鼠标,则不移动~~上面的改动使得onmousemove不起作用的~~~
      

  4.   

    不行的,我想作到如果按下鼠标,则层随鼠标移动,放开鼠标,则不移动~~上面的改动使得onmousemove不起作用的~~~
      

  5.   

    请问放开鼠标触发哪个事件?是onMouseUp吗?
    怎么我的上述事件不起作用?
      

  6.   

    <HTML>
    <head>
    <title>Windows</title>
    </head>
    <style>
        .bbb{
          border: solid black;
      border-width:1px;
     } 
    .memo{
      padding:10px;
              background-color:transparent;
              font-size:9pt;
              font-family:宋体;
      }
    .window{
      border-width:1px;
              background-color:#7396C6;
              font-size:9pt;
              font-family:宋体;
      z-index:100;
      /*filter:Alpha(Opacity=80,FinishOpacity=90,Style=1)*/
      }
    .windowTemp{
              border: solid #776a79;
      padding:10px;
      border-width:1px;
              background-color:transparent;
              font-size:9pt;
              font-family:宋体;
      }
      BODY{
      COLOR: #3e3c20; 
      FONT-SIZE: 9pt; 
      LINE-HEIGHT: 12pt; 
      SCROLLBAR-FACE-COLOR: #ffffff; 
      SCROLLBAR-HIGHLIGHT-COLOR: #ffffff; 
      SCROLLBAR-SHADOW-COLOR: #333333; 
      SCROLLBAR-3DLIGHT-COLOR: #333333; 
      SCROLLBAR-ARROW-COLOR: #797979; 
      SCROLLBAR-TRACK-COLOR: #ffffff; 
      SCROLLBAR-DARKSHADOW-COLOR: #ffffff
     }</style>
    <SCRIPT language="JScript">
    function selectstart()
    {    
    var tn=event.srcElement;
    if(tn.tagName.toLowerCase()!="input" && tn.tagName.toLowerCase()!="textarea" && tn.className.toLowerCase()!="text")
    {
    self.event.returnValue=false;
    }
    }
    function move()
     {
      if(event.button==1 && dragapproved)
       {
        var newleft=temp1+event.clientX-x
    var newtop=temp2+event.clientY-y
    eventsource.style.pixelLeft=newleft
        eventsource.style.pixelTop=newtop
        return false
       }
       else
       {
        oTemp.style.display="none";
    oWindow.style.posLeft=oTitle.style.posLeft=oTemp.style.posLeft
    oWindow.style.posTop=oTitle.style.posTop=oTemp.style.posTop
       }
     }
    var dragapproved=false;
    var eventsource,x,y;
    function finlish()
    {
    if(dragapproved)
    {
    oTemp.style.display="none";
    oWindow.style.posLeft=oTitle.style.posLeft=oTemp.style.posLeft
    oWindow.style.posTop=oTitle.style.posTop=oTemp.style.posTop
    }
    else
        dragapproved=false
    }
    function drags() //移动操作
     {
      var pe=event.srcElement.parentElement;
      if(event.srcElement.id=="oTitle")
       {
    window.event.cancelBubble = true
        dragapproved=true
    oTemp.style.posLeft=oWindow.style.posLeft
    oTemp.style.posTop =oWindow.style.posTop
    oTemp.style.width  =oWindow.style.width
    oTemp.style.height =oWindow.style.height
    oTemp.style.display="";
        eventsource=oTemp
        temp1=eventsource.style.pixelLeft
        temp2=eventsource.style.pixelTop
        x=event.clientX
        y=event.clientY
        document.onmousemove=move
       }
       else
        dragapproved=false
     }
    document.onmousedown=drags;
    document.onmouseup=finlish;
    document.ondragstart=new Function("self.event.returnValue=false");
    document.onselectstart=selectstart;
    </SCRIPT>
    <body leftmargin="0" topmargin="0">
    <div id="oTemp" class="windowTemp" style="position:absolute;display:none;z-index:300"></div>
    <div id="oTitle" style="position:absolute;top:expression((document.body.clientHeight-400)/2);left:expression((document.body.clientWidth-this.style.pixelWidth)/2);width:500;height:20;background-color:;z-index:200;padding:3px;">
    </div>
    <div id="oWindow" class="window" style="overflow:auto;position:absolute;top:expression((document.body.clientHeight-this.style.pixelHeight)/2);left:expression((document.body.clientWidth-this.style.pixelWidth)/2);width:500;height:400">
    <table width="100%" height="20" style="cursor:default;color:white;font-size:9pt;background-color:#21387B">
    <tr>
    <td width="30%" align="left">Windows</td>
    <td width="70%" align="right">X</td>
    </tr>
    </table>
    </div>
    <div id="oContent" class="memo" style="overflow:auto;position:absolute;top:0;left:70;width:expression(document.body.clientWidth-70);height:expression(document.body.clientHeight-100)">
    </div>
    </body>
    </html>