87,920
社区成员
发帖
与我相关
我的任务
分享
var Request = function(options){
var xmlHttpRequest;
try{
xmlHttpRequest = new XMLHttpRequest();
}catch(e){
xmlHttpRequest = new ActiveXObject('MSXML2.XMLHTTP');
}
this.xhr = xmlHttpRequest;
this.url = options.url || '';
this.data = options.data || '';
this.method = options.method || 'post';
this.onComplete = options.onComplete || function(){};
}
//封装ajax对象 a.Request({url:"url地址",data:"id=id&name=name",method:"post",onComplete=function(msg){alert(msg)}})
var $ = function(id){return 'string' == typeof id ? document.getElementById(id) : id}
//// 实例中 $("a")就能获取id为a 对象
var $Name = function(name){return document.getElementsByName(name);}
////实例中 $Name("a")就能获取tag为a 对象的数组
var $AddEvent = function(target, enentType, handle)
{
if(target.addEventListener)
target.addEventListener(enentType, handle, false);
else if(target.attachEvent)
target.attachEvent('on' + enentType, handle);
else
target['on' + enentType] = handle;
}
// 实例中 $AddEvent("a","click",func)---id为a的元素 的鼠标点击的时候 执行 func方法