var MoveDiv = function() { };         /** 
        * @deprecated 移动div的方法 
        * @param{id} id 要移动的层ID 
        */ 
        MoveDiv.Move = function(id) { 
            var o = document.getElementById(id);             o.onselectstart = function() { 
                return (false); 
            };             o.onmousedown = function(e) { 
                e = e || window.event; 
                var x = e.layerX || e.offsetX; 
                var y = e.layerY || e.offsetY;                 document.onmousemove = function(e) { 
                    e = e || window.event; 
                    o.style.left = (e.clientX - x) + "px"; 
                    o.style.top = (e.clientY - y) + "px"; 
                };                 document.onmouseup = function() { 
                    document.onmousemove = null; 
                }; 
            }; 
        } ------------- 
这个函数怎么在Firefox下好好的,怎么在IE下一抖一抖的? 还出现鼠标不按下也移动的状况。

解决方案 »

  1.   

    懒得问了,烦死了。来几个人接分来。我写两个函数算了,在IE和FF下用,气死我了。。
    --
    function DragDiv(ID) {
                var isIe = (document.all) ? true : false;
                if (isIe) {
                    MoveForIE(ID);
                }
                else {
                    MoveForFF(ID);
                }
            }看我牛不牛,哈哈。。老妖,过来接分了。。
      

  2.   

    八成是event的问题。
    function getEvent() {
         return window.event || arguments.callee.caller.arguments[0];
    }e = getEvent();
      

  3.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            html, body
            {
                font-size: 12px;
                margin: 0px;
                height: 100%;
            }
            .mesWindow
            {
                z-index: 1001;
                border: #666 1px solid;
                background: #fff;
            }
            .mesWindowTop
            {
                border-bottom: #eee 1px solid;
                margin-left: 4px;
                padding: 3px;
                font-weight: bold;
                text-align: left;
                font-size: 12px;
                height: 20px;
                cursor: move;
            }
            .mesWindowContent
            {
                margin: 4px;
                font-size: 12px;
                vertical-align: middle;
            }
            .mesWindow .close
            {
                text-align: right;
                cursor: pointer;
            }
        </style>    <script type="text/javascript">
            //判断浏览器是否为IE
            var isIe = (document.all) ? true : false;
            //弹出方法
            function showMessageBox(wTitle, content) {
                var msgw, msgh, bordercolor;
                msgw = 380; //提示窗口的宽度
                msgh = 120; //提示窗口的高度
                titleheight = 25 //提示窗口标题高度
                bordercolor = "#333"; //提示窗口的边框颜色 
                titlecolor = "#445588"; //提示窗口的标题颜色            closeWindow();
                var bWidth = parseInt(document.body.scrollWidth); //网页正文全文宽
                var bHeight = parseInt(window.screen.availHeight); //网页正文全文高
                var back = document.createElement("div"); //创建北京div对象
                back.id = "back";
                var styleStr = "top:0px;left:0px;position:absolute;background:#666;width:" + bWidth + "px;height:" + bHeight + "px;";
                styleStr += (isIe) ? "filter:alpha(opacity=50);" : "opacity:0.1;";
                back.style.cssText = styleStr;
                back.style.zIndex = "1000";
                if (isIe) {
                    back.innerHTML = "<iframe style='position: absolute; width:\"100%\"; height:\"100%\";' frameborder='0'> </iframe>";
                }
                document.body.appendChild(back);
                //showBackground(back, 50);
                var mesW = document.createElement("div"); //创建信息窗口对象div
                mesW.id = "mesWindow";
                mesW.className = "mesWindow";
                mesW.innerHTML = "<div class='mesWindowTop' onmousedown=\"DragDiv('mesWindow')\">"
                                  + "<table width='100%' height='100%'>"
                                  + "<tr>"
                                  + "<td>" + wTitle + "</td>"
                                  + "<td align='right'><a  onclick='closeWindow();' title='关闭窗口' class='close'>关闭</a></td>"
                                  + "</tr></table></div>"
                                  + "<div class='mesWindowContent' id='mesWindowContent'>" + content + "</div>"
                                  + "<div class='mesWindowBottom'></div>";
                //styleStr = "left:" + (((pos.x - wWidth) > 0) ? (pos.x - wWidth) : pos.x) + "px;top:" + (pos.y) + "px;position:absolute;width:" + wWidth + "px;";
                styleStr = "left:" + (bWidth - msgw) / 2 + "px;top:35%;position:absolute;width:" + msgw + "px;height:" + msgh + "px;text-align:center;";
                mesW.style.cssText = styleStr;
                document.body.appendChild(mesW);
            }
            function closeWindow() {
                if (document.getElementById('back') != null) {
                    document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
                }
                if (document.getElementById('mesWindow') != null) {
                    document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
                }
            }        function DragDiv(ID) {
                var isIe = (document.all) ? true : false;
                if (isIe) {
                    MoveForIE(ID);
                }
                else {
                    MoveForFF(ID);
                }
            }
            //拖拽图层
            var ms = 0;
            function MoveForIE(obj) {
                ms = obj;
                event.srcElement.setCapture();
                x = document.all(ms).style.pixelLeft - event.x;
                y = document.all(ms).style.pixelTop - event.y;
            }        document.onmousemove = function() {
                if (ms != "") {
                    document.all(ms).style.pixelLeft = x + event.x;
                    document.all(ms).style.pixelTop = y + event.y;
                }
            }        document.onmouseup = function() {
                if (ms != "") {
                    event.srcElement.releaseCapture();
                    ms = 0;
                }
            }        //测试弹出
            function testMessageBox(ev) {
                var messContent = "什么东西啊";
                showMessageBox('窗口标题', messContent);
            }
            //
            function MoveForFF(id) {
                var o = document.getElementById(id);            o.onselectstart = function() {
                    return (false);
                };            o.onmousedown = function(e) {
                    e = e || window.event;
                    var x = e.layerX || e.offsetX;
                    var y = e.layerY || e.offsetY;                document.onmousemove = function(e) {
                        e = e || window.event;
                        o.style.left = (e.clientX - x) + "px";
                        o.style.top = (e.clientY - y) + "px";
                    };                document.onmouseup = function() {
                        document.onmousemove = null;
                    };
                };
            }    </script></head>
    <body>
        <form id="form1" runat="server">
        <div style="text-align: left">
            <a href="#none" onclick="testMessageBox(event);">弹出窗口</a></div>
        <select>
            <option value="0">请选择</option>
        </select>
        <asp:dropdownlist id="DropDownList1" runat="server">
        </asp:dropdownlist>
        <select id="Select1">
            <option></option>
        </select>
        </form>
    </body>
    </html>
    --
    这是源码
      

  4.   

    JF
    唉,最近也被JS搞得好头疼
    有时候在IE下好的,FF下不行
    有时候IE下好的,FF下也是好的,Chrome下不行
    郁闷死