JavaScript-封装的库
/*
***Cookie
*/
function setCookie(name,value,iDay)
{
//设置Cookie
var oDate=new Date();
oDate.setDate(oDate.getDate()+iDay);
document.cookie=name+"="+value+";expires="+oDate;
}
function getCookie(name)
{
//获取Cookie
var oDate=new Date();
var arr=document.cookie.split(';');
for(var i=0;i<arr.length;i++)
{
var arr2=arr[i].split('=');
if(arr2[0]==name){
return arr2[1];
}
}
return '';
}
function removeCookie(name)
{
//删除Cookie
document.cookie(name,1,-1);
}
/*
****Cookie
*/
/*
****滚动条滚动的距离
*/
function getPos(ev)
{
var scrollLeft=document.documentElement.scrollLeft||document.body.scrollLeft;
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
return {x:scrollLeft,y:scrollTop};
}
/*
****滚动条滚动的距离
*/
/*
****事件绑定
*/
function myAddEvent(obj,ev,fn)
{
if(obj.attachEvent)
{
obj.attachEvent('on'+ev,fn);
}
else
{
obj.addEventListener(ev,fn,false);
}
}
/*
****事件绑定
*/
/*
****AJAX
*/
function ajax(url, fnSucc, fnFaild)
{
//1.创建Ajax对象
if(window.XMLHttpRequest)
{
var oAjax=new XMLHttpRequest();
}
else
{
var oAjax=new ActiveXObject("Microsoft.XMLHTTP");
}
//2.连接服务器(打开和服务器的连接)
oAjax.open('GET', url, true);
//3.发送
oAjax.send();
//4.接收
oAjax.onreadystatechange=function ()
{
if(oAjax.readyState==4)
{
if(oAjax.status==200)
{
//alert('成功了:'+oAjax.responseText);
fnSucc(oAjax.responseText);
}
else
{
//alert('失败了');
if(fnFaild)
{
fnFaild();
}
}
}
};
}
/*
****AJAX
*/