<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function ShowDiv(){
Div1.style.display = "";
}
function HideMe(obj){
obj.style.display = "none";
}
//-->
</SCRIPT>
</HEAD><BODY ondblclick="ShowDiv()">
<DIV id="Div1" onmousedown="HideMe(this)" style="display:none">fdsafdsfdasfdasfasd</DIV>
</BODY>
</HTML>

解决方案 »

  1.   

    <html>
    <script>
    var d=0
    function find(qq){
    d=qq
    x=event.clientX-d.style.pixelLeft
    y=event.clientY-d.style.pixelTop
    }
    function dragit(){
    if(d==0)return false
    else{
    d.style.pixelLeft=event.clientX-x
    d.style.pixelTop=event.clientY-y
    }
    }
    </script>
    <body style="margin:0" onmousemove="dragit()" onmouseup="d=0">
    <div id=aa style="width:100pt;height:100pt;background:black;position:absolute" onmousedown="find(aa)"></div>
    </body>
    </html>
      

  2.   

    托动不行,但是能慢慢划出!!!
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head>
    <script>window.onresize = resizeDiv;
    window.onerror = function(){}
    var sdivTop,sdivLeft,sdivWidth,sdivHeight,sdocHeight,sdocWidth,sobjTimer,i = 0;
    function getMsg()
    {
     try{
     sdivTop = parseInt(document.getElementById("location").style.top,10)
     sdivLeft = parseInt(document.getElementById("location").style.left,10)
     sdivHeight = parseInt(document.getElementById("location").offsetHeight,10)
     sdivWidth = parseInt(document.getElementById("location").offsetWidth,10)
     sdocWidth = document.body.clientWidth - 20;
     sdocHeight = document.body.clientHeight;
     document.getElementById("location").style.top = parseInt(document.body.scrollTop,10) + sdocHeight + 10;//  divHeight
     document.getElementById("location").style.left = parseInt(document.body.scrollLeft,10) + sdocWidth - sdivWidth
     document.getElementById("location").style.visibility="visible"
     sobjTimer = window.setInterval("moveDiv()",10)
     }
     catch(e){}
    }function resizeDiv()
    {
     i+=1
     if(i>500) closeDiv()
     try{
     sdivHeight = parseInt(document.getElementById("location").offsetHeight,10)
     sdivWidth = parseInt(document.getElementById("location").offsetWidth,10)
     sdocWidth = document.body.clientWidth;
     sdocHeight = document.body.clientHeight;
     document.getElementById("location").style.top = sdocHeight - sdivHeight + parseInt(document.body.scrollTop,10)
     document.getElementById("location").style.left = sdocWidth - sdivWidth + parseInt(document.body.scrollLeft,10) -20
     }
     catch(e){}
    }function moveDiv()
    {
     try
     {
     if(parseInt(document.getElementById("location").style.top,10) <= (sdocHeight - sdivHeight + parseInt(document.body.scrollTop,10)))
     {
     window.clearInterval(sobjTimer)
     sobjTimer = window.setInterval("resizeDiv()",1)
     }
     sdivTop = parseInt(document.getElementById("location").style.top,10)
     document.getElementById("location").style.top = sdivTop - 1
     }
     catch(e){}
    }
    function closeDiv()
    {
     document.getElementById('location').style.visibility='hidden';
     if(sobjTimer) window.clearInterval(sobjTimer)
    }
    </script>
    <body ondblclick="getMsg()">
    <DIV id=location style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; FILTER: Alpha(Opacity=70); VISIBILITY: hidden; BORDER-LEFT: 1px solid; WIDTH: 220px; BORDER-BOTTOM: 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: 80px; BACKGROUND-COLOR: #ededed">
    <TABLE onclick=" document.getElementById('location').style.visibility='hidden';" 
    cellSpacing=0 cellPadding=5 width="100%" bgColor=#ededed border=0>
    <tr><td>此视窗10秒后自动关闭</TD></TR></TABLE>
    </DIV>
    </body></html>
      

  3.   

    这是我以前写的一个打开并拖动层的代码:<html><body onLoad="setDrag()"  >                <table width="93%" height="19" border="1">
                        <tr>
                            <td width="17%" bgcolor="#CCCCFF"><div align="center"><a href="#now" ondblclick="openDivKenmei()"><strong>dbclick</strong></div></td>
                            <td width="83%"><input type="text" size="110" disabled value=""></td>
                        </tr>
                    </table>
                    <br><div id='div_kenmei' style="DISPLAY: none; FONT-SIZE: 10pt; Z-INDEX: 2; WIDTH: 300px;POSITION: absolute; HEIGHT: 75px; BACKGROUND-COLOR: white" >
        <form name="frmKenmei" method="post">
            <table width="300" bgcolor="white" border="1" rules="none">
                <td>
                    <div style="background-color:#D7EFFF;Border-bottom:1px solid skyblue">
                        <table width="100%">
                            <tr>
                                <td width="55%" aligh="left" style="WORD-WRAP: break-word">TEST</td>
                                <td align="right">
                                    &nbsp;
                                    <a href="#now" onClick="closeDivKenmei()">CLOSE</a>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <table width="100%">
                        <tr>
                            <td colspan="2">
                                INPUT<input type="text" name="SBJCT_NM" value="" maxLength="64" onChange="checkChange()" nValue="画面表示名称">
                            </td>
                        </tr>
                     </table>
                </td>
            </table>
            <input type="hidden" name="ItemIndex" value="SBJCT_NM">
        </form>
    </div></body>
    </html>
      

  4.   

    这个是JS代码,你自己加进去
    function beginDrag() {
        wLocationX = event.clientX + document.body.scrollLeft;
        wLocationY = event.clientY + document.body.scrollTop;    if((event.srcElement.disabled==false)&&(event.srcElement.tagName!="INPUT")&&(event.srcElement.tagName!="SELECT")&&(event.srcElement.tagName!="DIV"))
        {
            dragThis = event.srcElement;        while(dragThis.id != "div_kenmei" && dragThis.id != "div_shounin" && dragThis.id != "div_kigen" &&
                  dragThis.id != "div_sentaku" && dragThis.id != "div_textarea" && dragThis.id != "div_option" &&
                  dragThis.id != "div_optnSlt" && dragThis.id != "div_label"){
                dragThis = dragThis.parentElement;
                if (dragThis == null) { return }
            }
            oldX = (event.clientX + document.body.scrollLeft);
            oldY = (event.clientY + document.body.scrollTop); 
        }
    }function endDrag() 
    {
    dragThis = null;
    }function dragIt() 
    {
    if (dragThis == null) { return };                  
            newX = (event.clientX + document.body.scrollLeft);
            newY = (event.clientY + document.body.scrollTop);
            var distanceX = (newX - oldX);
            var distanceY = (newY - oldY);
            oldX = newX;
            oldY = newY;                  
            dragThis.style.pixelLeft += distanceX;
            dragThis.style.pixelTop += distanceY;        
            event.returnValue = false;
    }function setDrag() 
    {
        document.onmousemove = dragIt;
        document.onmousedown = beginDrag;
        document.onmouseup = endDrag;
        oldX=oldY=newX=newY=0, dragThis=null;}function setPosition(vDiv){    vDiv.style.display = "";    var rightedge = document.body.clientWidth-event.clientX;
        var bottomedge = document.body.clientHeight-event.clientY;    if (rightedge < vDiv.offsetWidth){
            vDiv.style.left = wLocationX - vDiv.offsetWidth;
        }else{
            vDiv.style.left = wLocationX;
        }    if (bottomedge < vDiv.offsetHeight){
            vDiv.style.top = wLocationY - vDiv.offsetHeight;
        }else{
            vDiv.style.top = wLocationY;
        }
    }
    function openDivKenmei(){
        setPosition(div_kenmei);
        div_kenmei.style.visibility = "visible";
        return false;
    }
    function closeDivKenmei(){
        div_kenmei.style.visibility = "hidden";
    }
      

  5.   


    我和在一起的代码:
    <script language="javascript">var wLocationX;
    var wLocationY;function beginDrag() {
        wLocationX = event.clientX + document.body.scrollLeft;
        wLocationY = event.clientY + document.body.scrollTop;    if((event.srcElement.disabled==false)&&(event.srcElement.tagName!="INPUT")&&(event.srcElement.tagName!="SELECT")&&(event.srcElement.tagName!="DIV"))
        {
            dragThis = event.srcElement;        while(dragThis.id != "div_kenmei" && dragThis.id != "div_shounin" && dragThis.id != "div_kigen" &&
                  dragThis.id != "div_sentaku" && dragThis.id != "div_textarea" && dragThis.id != "div_option" &&
                  dragThis.id != "div_optnSlt" && dragThis.id != "div_label"){
                dragThis = dragThis.parentElement;
                if (dragThis == null) { return }
            }
            oldX = (event.clientX + document.body.scrollLeft);
            oldY = (event.clientY + document.body.scrollTop); 
        }
    }function dragIt() 
    {
    if (dragThis == null) { return };                  
            newX = (event.clientX + document.body.scrollLeft);
            newY = (event.clientY + document.body.scrollTop);
            var distanceX = (newX - oldX);
            var distanceY = (newY - oldY);
            oldX = newX;
            oldY = newY;                  
            dragThis.style.pixelLeft += distanceX;
            dragThis.style.pixelTop += distanceY;        
            event.returnValue = false;
    }function endDrag() 
    {
    dragThis = null;
    }function setDrag() 
    {
    document.onmousemove = dragIt;
        document.onmousedown = beginDrag;
        document.onmouseup = endDrag;
        oldX=oldY=newX=newY=0, dragThis=null;}function setPosition(vDiv){    vDiv.style.display = "";    var rightedge = document.body.clientWidth-event.clientX;
        var bottomedge = document.body.clientHeight-event.clientY;    if (rightedge < vDiv.offsetWidth){
            vDiv.style.left = wLocationX - vDiv.offsetWidth;
        }else{
            vDiv.style.left = wLocationX;
        }    if (bottomedge < vDiv.offsetHeight){
            vDiv.style.top = wLocationY - vDiv.offsetHeight;
        }else{
            vDiv.style.top = wLocationY;
        }
    }
    function openDivKenmei(){
        setPosition(div_kenmei);
        div_kenmei.style.visibility = "visible";
        return false;
    }
    function closeDivKenmei(){
        div_kenmei.style.visibility = "hidden";
    }
    </script>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB2312">
    <meta http-equiv="Content-Style-Type" content="text/css"></head><body onLoad="setDrag()"  >                <table width="93%" height="19" border="1">
                        <tr>
                            <td width="17%" bgcolor="#CCCCFF"><div align="center"><a href="#now" ondblclick="openDivKenmei()"><strong>dbclick</strong></div></td>
                            <td width="83%"><input type="text" size="110" disabled value=""></td>
                        </tr>
                    </table>
                    <br><div id='div_kenmei' style="DISPLAY: none; FONT-SIZE: 10pt; Z-INDEX: 2; WIDTH: 300px;POSITION: absolute; HEIGHT: 75px; BACKGROUND-COLOR: white" >
        <form name="frmKenmei" method="post">
            <table width="300" bgcolor="white" border="1" rules="none">
                <td>
                    <div style="background-color:#D7EFFF;Border-bottom:1px solid skyblue">
                        <table width="100%">
                            <tr>
                                <td width="55%" aligh="left" style="WORD-WRAP: break-word">TEST</td>
                                <td align="right">
                                    &nbsp;
                                    <a href="#now" onClick="closeDivKenmei()">CLOSE</a>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <table width="100%">
                        <tr>
                            <td colspan="2">
                                INPUT<input type="text" name="SBJCT_NM" value="" maxLength="64" >
                            </td>
                        </tr>
                     </table>
                </td>
            </table>
            <input type="hidden" name="ItemIndex" value="SBJCT_NM">
        </form>
    </div></body>
    </html>