现在是alert("lin");这段代码都实现不了~~~~~~~~~ 

解决方案 »

  1.   

    后面有错 alert("lin");不出来的
      

  2.   

    一般都是用document.body.onmouseup 而不用html元素的onmouseup
      

  3.   

    代码不全
    请贴出调用onmouseup事件的代码段PS:楼主该结一些帖子了
      

  4.   

    <html><head>
    <title>测试可动div</title>
    <script language='javascript' type='text/javascript'>
    function down(mevent,id)
    {   
        var ev=mevent;
        var bool=false;
        if(document.all&&ev.button==1)
        {
            bool=true;
        }
        else
        {
            if(ev.button==0)
            {
                bool=true;
            }
        }
        if(bool==true)
        {        var div=window.document.getElementById(id);
            div.onmouseup=up;
            var x=parseInt(ev.clientX-div.offsetLeft);
            var y=parseInt(ev.clientY-div.offsetTop);
            window.document.documentElement.onmousemove=function(mEvent)
            {
                if(document.all)
                {
                    div.style.left=(ev.clientX-x)+"px";
                    div.style.top=(ev.clientY-y)+"px";
                
                }
                else
                {
                    div.style.left=(mEvent.clientX-x)+"px";
                    div.style.top=(mEvent.clientY-y)+"px";
                }
            }
        }
    }function up()
    {
        window.document.documentElement.onmousemove=null;
    }
    </script>
    </head>
    <body>
    <div id="oDiv" onmousedown="down(event,'oDiv')" style="cursor:move;position:absolute;width:100px;height:60px;border:1px solidsilver;left:100px;top:100px;z-index:9999;"></div>
    </body></html>我把代码复制到一个新页面中,功能正常~~~~可就是在我要使用的那个页面~~~出异常
      

  5.   

    http://topic.csdn.net/u/20080702/17/a9c334f0-e983-4981-9dc2-b4cea201e0d1.html?795201025
    ^^,可以供参考下。
      

  6.   

    function down(mevent,id) 
    {  
        var ev=mevent; 
        var bool=false; 
        if(document.all&&ev.button==1) 
        { 
            bool=true; 
        } 
        else 
        { 
            if(ev.button==0) 
            { 
                bool=true; 
            } 
        } 
        if(bool==true) 
        {         var div=window.document.getElementById(id); 
            div.onmouseup=up;                           //为"DIV"注册onmouseup事件
            var x=parseInt(ev.clientX-div.offsetLeft); 
            var y=parseInt(ev.clientY-div.offsetTop); 
            window.document.documentElement.onmousemove=function(mEvent) 
            { 
                if(document.all) 
                { 
                    div.style.left=(ev.clientX-x)+"px"; 
                    div.style.top=(ev.clientY-y)+"px"; 
                
                } 
                else 
                { 
                    div.style.left=(mEvent.clientX-x)+"px"; 
                    div.style.top=(mEvent.clientY-y)+"px"; 
                } 
            } 
        } 
    } function up() 

        window.document.documentElement.onmousemove=null; 

    </script> 
    </head> 
    <body> 
    <div id="oDiv" onmousedown="down(event,'oDiv')" style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;"> </div> 
    </body> </html> 
      

  7.   

    <script language="javascript">
    function down(mevent,id) 
    {  
        var ev=mevent; 
        var bool=false; 
        if(document.all&&ev.button==1) 
        { 
            bool=true; 
        } 
        else 
        { 
            if(ev.button==0) 
            { 
                bool=true; 
            } 
        } 
        if(bool==true) 
        {         var div=window.document.getElementById(id); 
           // div.onmouseup=up;                          //为"DIV"注册onmouseup事件 
            var x=parseInt(ev.clientX-div.offsetLeft); 
            var y=parseInt(ev.clientY-div.offsetTop); 
            window.document.documentElement.onmousemove=function(mEvent) 
            { 
                if(document.all) 
                { 
                    div.style.left=(ev.clientX-x)+"px"; 
                    div.style.top=(ev.clientY-y)+"px"; 
                
                } 
                else 
                { 
                    div.style.left=(mEvent.clientX-x)+"px"; 
                    div.style.top=(mEvent.clientY-y)+"px"; 
                } 
            } 
        } 
    } function up()

        window.document.documentElement.onmousemove=null; 

    </script> 
    </head> 
    <body> 
    <div id="oDiv" onmousedown="down(event,'oDiv')" onmouseup="up(event)" style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;"> </div> 
    </body> </html> 
      

  8.   

    抓狂了,不知道是浏览器的原因还是`~~~~~~~~~~~~
    我用的是ASP.NET.最后我把代码改了
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">//就是这段
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>无标题页</title>
        <script type="text/javascript" language="javascript">    
    function down(mevent,id)
    {   
        var ev=mevent;
        var bool=false;
        dd=id;
        if(document.all&&ev.button==1)
        {
            bool=true;
        }
        else
        {
            if(ev.button==0)
            {
                bool=true;
            }
        }
        if(bool==true)
        {        var div=window.document.getElementById(id);
            var x=parseInt(ev.clientX-div.offsetLeft);
            var y=parseInt(ev.clientY-div.offsetTop);
            window.document.documentElement.onmousemove=function(mEvent)
            {
                if(document.all)
                {
                    div.style.left=(ev.clientX-x)+"px";
                    div.style.top=(ev.clientY-y)+"px";
                
                }
                else
                {
                    div.style.left=(mEvent.clientX-x)+"px";
                    div.style.top=(mEvent.clientY-y)+"px";
                }
            }
        }
    }function up()

        window.document.documentElement.onmousemove=null; 

        </script>
    </head>
    <body>
        <div id="oDiv" onmousedown="down(event,'oDiv')" onmouseup="up()" style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;"></div>
    </body>
    </html>最后发现在火狐浏览器里能正常运行!
    在IE浏览器里只有把下面这段代码去掉才能正常运行了!!请问一下这是什么原因?
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">