愚见未来

人的思想时时刻刻都在进步,如果你早上起床,想起昨天所做的事情是那么幼稚和迂腐,那么恭喜你,你又变得成熟一点了!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

js 创建一个浮动div

Posted on 2009-12-25 14:51  愚见未来  阅读(5451)  评论(0编辑  收藏  举报
//关闭DIV MENU
        function MenuClose()
        {
            var MenuDiv = document.getElementById("MenuDiv");
            if(MenuDiv != null)
            {
                document.body.removeChild(MenuDiv);
            }
        }
        //创建menu
         function MenuPanel(opflag,operid, left, top)
         {
            var MenuDiv = document.getElementById("MenuDiv");
            if(MenuDiv != null)
            {
                document.body.removeChild(MenuDiv);
            }
           
            var useflag = "停用帐号";
            var flag=opflag;
            if (flag == "0")
            {
                useflag = "停用帐号";
            }
            else
            {
                useflag = "激活帐号";
            }
            MenuDiv = document.createElement("div");
            MenuDiv.id = "MenuDiv";
            MenuDiv.onmouseleave = function()
            {
                MenuClose();
            }
            MenuDiv.style.position = "absolute";  
            MenuDiv.style.setAttribute("zIndex" ,"201");
            MenuDiv.style.setAttribute("backgroundColor" ,"#EFEFEF");
            MenuDiv.style.setAttribute("Font" ,"10pt");
            MenuDiv.style.setAttribute("width" ,60);
            MenuDiv.style.setAttribute("left" ,left);
            MenuDiv.style.setAttribute("top" ,top);
            MenuDiv.innerHTML = "<table width=\"100%\">"
                                +"<tr><td onclick=\"javascript:RedirectUrl(1,'" + flag + "','" + operid + "');MenuClose();\" style=\"cursor:hand;height:20px;Color:blue;\"  onmouseover=\"this.style.backgroundColor='#FFD76B';\" onmouseout=\"this.style.backgroundColor='#EFEFEF';\" align=\"left\" valign=\"top\">"+useflag+"</td></tr>"
                                +"<tr><td onclick=\"RedirectUrl(0,0,'" + operid + "')\" style=\"cursor:hand;height:20px;Color:blue;\" onmouseover=\"this.style.backgroundColor='#FFD76B';\" onmouseout=\"this.style.backgroundColor='#EFEFEF';\" align=\"left\" valign=\"top\">修改帐号</td></tr>"
                                +"<tr><td onclick=\"javascript:RedirectUrl(4,0,'" + operid + "')\" style=\"cursor:hand;height:20px;Color:blue;\" onmouseover=\"this.style.backgroundColor='#FFD76B';\" onmouseout=\"this.style.backgroundColor='#EFEFEF';\" align=\"left\" valign=\"top\">重设密码</td></tr>"
                                +"<tr><td onclick=\"RedirectUrl(2,0,'" + operid + "')\" style=\"cursor:hand;height:20px;Color:blue;\" onmouseover=\"this.style.backgroundColor='#FFD76B';\" onmouseout=\"this.style.backgroundColor='#EFEFEF';\" align=\"left\" valign=\"top\">角色管理</td></tr>"
                                +"<tr><td onclick=\"javascript:RedirectUrl(3,0,'" + operid + "')\" style=\"cursor:hand;height:20px;Color:blue;\" onmouseover=\"this.style.backgroundColor='#FFD76B';\" onmouseout=\"this.style.backgroundColor='#EFEFEF';\" align=\"left\" valign=\"top\">删除帐号</td></tr>"
                                +"</table>";
             document.body.appendChild(MenuDiv);
         }
         //获取控件的高度和宽度
         function getAbsolutePos(e)
         {
            var t=e.offsetTop;  
            var l=e.offsetLeft;  
            while(e=e.offsetParent)
            {  
                t+=e.offsetTop;  
                l+=e.offsetLeft;  
            }
           
            var pos = { x: l, y: t };
            return pos;
         }