function MouseMove()    
  {    
  if(Obj!=null)    
  {    
  Obj.style.left  =  event.x-Obj.l;    
  Obj.style.top  =  event.y-Obj.t;    
  }    
  }    你可以加alert试试,在运行event.x - Obj.l的时候 Obj.l还不存在,是undefined,当然会报错

解决方案 »

  1.   

    你又开了一个帖子啊- -| | |
    你这次的问题是obj的问题了
    第一次obj=shade1;这时候走down,move up没有问题,但是在up之后obj=null了
    第二次obj=null;  你这时候程序怎么能走哪?所以你只要在你的早先发的那个程序里稍微小改一下就可以了我建议你继续用原来的bIsCatchFlyBar那个变量
    下面是我对你原先程序的修改
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style>
    html,body{
    margin: 0px;/*-- 取消页面边界 --*/
    /*-- 滚动条样式 for IE 5.5+--*/
    scrollbar-face-color: #f6f6f6;
    scrollbar-highlight-color: #ffffff;
    scrollbar-shadow-color: #cccccc;
    scrollbar-3dlight-color: #cccccc;
    scrollbar-arrow-color: #330000;
    scrollbar-track-color: #f6f6f6;
    scrollbar-darkshadow-color: #ffffff;
    /*background-color: #00B2EB;-- 页面背景 --*/
    }
    body,td,th {
    font-size: 12px;/*-- 页面字号 --*/
    color: #000000;/*-- 页面字体颜色 --*/
    font-family:Verdana, Arial, Helvetica, sans-serif;/*-- 页面字体 --*/
    }
    .Msg_Bg {
    position:absolute;
    left: 0;
    top: 0;
    width: 100%;
    height:100%;
    filter:alpha(opacity=60);
    -moz-opacity:.6;
    opacity:.6;
    background-color: #cccccc;
    z-index: 1;
    position: absolute;
    }
    .Msg_Div_Coutent {
    position:absolute;
    left: 10%;
    top: 10%;
    -moz-opacity:.6;
    opacity:.6;
    z-index: 1;
    position: absolute;
    cursor:move;
    background-color:#FF0000;
    height:100px;
    }
    </style>
    <script language="javascript">
    // JavaScript Document
    function CElement(TextHtml)
    {
      var shade = document.createElement('div');
    var shade1 = document.createElement('div');
    shade.className = "Msg_Bg";
    shade.id    ="MsgBoxF";
    shade1.className = "Msg_Div_Coutent";
    shade1.id  ="MsgBoxC";
    document.body.insertBefore(shade, document.getElementById("body"));
    document.body.insertBefore(shade1, document.getElementById(shade));
    var ptable = document.getElementById('shade1');
    if (shade.style.display == 'none') return;
    var ch = document.body.clientHeight, sh = document.body.scrollHeight, st=document.body.scrollTop;
    shade.style.height = (sh > ch ? sh : ch) + 'px';
    shade.style.width = document.body.clientWidth + 'px';
    //shade1.style.width = document.body.clientWidth/2 + 'px';
    var pos = [], pw;
    if (ptable) {
    pos = getPosXY(ptable);
    pw = ptable.offsetWidth || 760;
    } else {
    pw = 500;
    pos[0] = (document.body.clientWidth-pw)/2+50;
    pos[1] = (ch-(shade1.offsetHeight || 300))/2-200;
    }
    if (navigator.product && navigator.product == 'Gecko') {
    pw -= 40;
    }
    shade1.style.left = pos[0] + 'px';
    shade1.style.top = pos[1] + 'px';
    //shade1.style.height =ch/2 + 'px'; MsgBoxC.attachEvent('onmousedown',MouseDown);
     MsgBoxC.attachEvent('onmousemove',MouseMove);
     MsgBoxC.attachEvent('onmouseup',MouseUp);
      shade1.innerHTML=TextHtml;
    }
    var bIsCatchFlyBar = false; 
    var dragClickX = 0; 
    var dragClickY = 0; 
    function MouseDown(){ 
        bIsCatchFlyBar = true;
        var x=event.x+document.body.scrollLeft; 
        var y=event.y+document.body.scrollTop; 

        dragClickX=x-MsgBoxC.style.pixelLeft; 
        dragClickY=y-MsgBoxC.style.pixelTop; 
        MsgBoxC.setCapture();
        //document.onmousemove =moveFlyBar;

    function MouseUp(){ 
        bIsCatchFlyBar = false; 
        MsgBoxC.releaseCapture(); 
       // document.onmousemove = null; 

     
    function MouseMove(){ 
        
        if(bIsCatchFlyBar){ 
       
            MsgBoxC.style.left = event.x+document.body.scrollLeft-dragClickX; 
            MsgBoxC.style.top = event.y+document.body.scrollTop-dragClickY; 
            }
    }
    </script></head><body>
    <script language='javascript'>CElement("123123123"); </script> 
    </body>
    </html>