Chinaunix首页 | 论坛 | 博客
  • 博客访问: 339183
  • 博文数量: 70
  • 博客积分: 2068
  • 博客等级: 大尉
  • 技术积分: 687
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-29 14:58
文章分类

全部博文(70)

文章存档

2012年(1)

2009年(69)

我的朋友

分类: 系统运维

2009-05-05 08:24:19

 键盘按键代码:

code = (e.charCode) ? e.charCode :

       ((e.keyCode) ? e.keyCode :

       ((e.which) ? e.which : 0));

 

生成Xml文档对象:

function strToxml(str)

{

        var xml = null;

        if(window.ActiveXObject)

        {

                xml = new ActiveXObject("Microsoft.XMLDOM");

                xml.loadXML(str);

        } else {

                var parser = new DOMParser();

                xml = parser.parseFromString(str, "text/xml");

        }

        return xml;

}

 

生成XMLHTTPREQUEST对象:

function createXmlHttpRequestObject()

{

  var xmlHttp;

  try

  {

    xmlHttp = new XMLHttpRequest();

  }

  catch(e)

  {

    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",

                                    "MSXML2.XMLHTTP.5.0",

                                    "MSXML2.XMLHTTP.4.0",

                                    "MSXML2.XMLHTTP.3.0",

                                    "MSXML2.XMLHTTP",

                                    "Microsoft.XMLHTTP");

    for (var i=0; i

    {

      try

 

      {

        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);

      }

      catch (e) {}

    }

  }

  if (!xmlHttp)

    alert("Error creating the XMLHttpRequest object.");

  else

return xmlHttp;

 

浏览器版本判断:

var ie5 = window.navigator.userAgent.indexOf( "MSIE 5" )!=-1;

var tplsource = parent.window.frames.dataFrame.window;

var NS4 = (document.layers) ? true:false;

var IE4 = (document.all) ? true:false;

var DOM = (document.getElementById) ? true:false;

if (IE4) DOM = false;

 

function popUp()

{

        var layerName = "presending";

        if (NS4)

                document.layers[layerName].visibility = "show";

        else if (DOM)

                document.getElementById(layerName).style.display = "block";

        else

                document.all[layerName].style.display = "block";

}

 

文本自动选定范围:

function selectRange(oText, start, length)

{

  if (oText.createTextRange)

  {

    //IE

    var oRange = oText.createTextRange();

    oRange.moveStart("character", start);

    oRange.moveEnd("character", length - oText.value.length);

    oRange.select();

 

  }

  else

    // FF

    if (oText.setSelectionRange)

    {

      oText.setSelectionRange(start, length);

    }

  oText.focus();

}

 

getElementById方法通用化方法定义:

function getElementById(aID){
 var element = null;
  
 if (isMozilla || isIE5)
   element = document.getElementById(aID)
 else if (isNetscape4)
   element = document.layers[aID]
 else if (isIE4)
   element = document.all[aID];
  
 return element;
}
阅读(867) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~