function ajax(){
   
             //    doc.innerhtml='loading...';
            ////创造对象
            var xmlhttp;
            try
            {
                if (window.activexobject){
                    /* 不要删除以下注释,这部分不是注释 */
                    @*/
                    (@_jscript_version >= 5)
                    try {
                      xmlhttp = new activexobject("msxml2.xmlhttp");
                    } catch (e) {
                      try {
                        xmlhttp = new activexobject("microsoft.xmlhttp");
                      } catch (e) {
                        xmlhttp = false;
                      }
                    }
                    @end @*/
                }else{
                    xmlhttp=new xmlhttprequest();
                }
                if (!xmlhttp && typeof xmlhttprequest != 'undefined') {
                  xmlhttp = new xmlhttprequest();
                }
            }
            catch(e)
            {
            alert(e.message);
            }
            //alert(xmlhttp);
            if(!xmlhttp)
            {
            alert("你的浏览器不支持xmlhttp对象,所以一些功能无法使用,建议使用高版本的浏览器!!");
            return;
            }

//    
            ///函数主题
                this.getdata=function(url,data,dodata)
                {
                    var verbs =data;
                   // alert(data);
                    xmlhttp.open("post", url,true);

                        xmlhttp.onreadystatechange=function(){
                            if (xmlhttp.readystate==4){
                                dodata(xmlhttp);                 
                            }
                        }
                    xmlhttp.setrequestheader("content-length",verbs.length);
                    xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded");
                    xmlhttp.send(verbs);
                }
                /////
                this.geturldata=function(url,data,dodata)
                {
                    xmlhttp.open("get",url,true);

                    xmlhttp.onreadystatechange = function() {

                    if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {
                      dodata(xmlhttp);
                     status.setstatusshow(false);
                    }
                    else
                    {
                      status.showinfo("加载中...");
                    }
                 
                    }
                     xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded");
                    xmlhttp.send(null);
                }
                this.getformdata=function(demo)
                {
                alert(demo);
                }
            ///函数主题
}
/**
 * @author zxub 2006-06-01
 * 状态信息显示类,用var status=new function()定义,可以静态引用其中的方法
 * 一般情况下为function status(),这样不能静态引用其中的方法,需要通过对象来引用
 */
var status=new function()
{
    this.statusdiv=null;
   
    /**
     * 初始化状态显示层
     */
 this.init=function()
 {
     if (this.statusdiv!=null)
     {
         return;
     }
  var body = document.getelementsbytagname("body")[0];
  var div = document.createelement("div");
  div.style.position = "absolute";
  div.style.top = "50%";
  div.style.left = "50%";
  div.style.width = "280px";
  div.style.margin = "-50px 0 0 -100px";  
  div.style.padding = "15px";
  div.style.backgroundcolor = "#353555";
  div.style.border = "1px solid #cfcfff";
  div.style.color = "#cfcfff";
  div.style.fontsize = "14px";
  div.style.textalign = "center";
  div.id = "idstatus";
  body.appendchild(div);
  div.style.display="none";
  this.statusdiv=document.getelementbyid("idstatus");
 }
 
 /**
  * 设置状态信息
  * @param _message:要显示的信息
  */ 
 this.showinfo=function(_message)
 {  
     if (this.statusdiv==null)
     {
         this.init();
     } 
     this.setstatusshow(true);
     this.statusdiv.innerhtml = _message;    
 }
 
 /**
  * 设置状态层是否显示
  * @param _show:boolean值,true为显示,false为不显示
  */
 this.setstatusshow=function(_show)
 {  
     if (this.statusdiv==null)
     {
         this.init();
     }
     if (_show)
     {
         this.statusdiv.style.display="";
     }
     else
     {
         this.statusdiv.innerhtml="";
         this.statusdiv.style.display="none";
     }
 }
}
function getposition(element) {
    var result = new object();
    result.x = 0;
    result.y = 0;
    result.width = 0;
    result.height = 0;
    if (element.offsetparent) {
        result.x = element.offsetleft;
        result.y = element.offsettop;
        var parent = element.offsetparent;
        while (parent) {
            result.x = parent.offsetleft;
            result.y = parent.offsettop;
            var parenttagname = parent.tagname.tolowercase();
            if (parenttagname != "table" &&
                parenttagname != "body" &&
                parenttagname != "html" &&
                parenttagname != "div" &&
                parent.clienttop &&
                parent.clientleft) {
                result.x = parent.clientleft;
                result.y = parent.clienttop;
            }
            parent = parent.offsetparent;
        }
    }
    else if (element.left && element.top) {
        result.x = element.left;
        result.y = element.top;
    }
    else {
        if (element.x) {
            result.x = element.x;
        }
        if (element.y) {
            result.y = element.y;
        }
    }
    if (element.offsetwidth && element.offsetheight) {
        result.width = element.offsetwidth;
        result.height = element.offsetheight;
    }
    else if (element.style && element.style.pixelwidth && element.style.pixelheight) {
        result.width = element.style.pixelwidth;
        result.height = element.style.pixelheight;
    }
    return result;
}

posted on 2009-10-28 16:03 sanmao 阅读(754) 评论(2)    

feedback:
# re: ajax|消息提示框|js获取html绝对位置 封装
2011-11-15 09:32 |
按照博主说的,回去试试  回复  
  
# re: ajax|消息提示框|js获取html绝对位置 封装
2011-11-15 09:33 |
不知道、能不能行  回复  
  

只有注册用户后才能发表评论。


网站导航:
              
 

常用链接

留言簿(5)

ajax|消息提示框|js获取html绝对位置 封装 -凯发k8网页登录

搜索

  •  

最新评论

阅读排行榜

评论排行榜

网站地图