<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button id="reg">点击</button>
<script language="javascript">
var A=A||{};
A.on=function(dom,type,fn){
if(document.addEventListener){
return function(dom,type,fn){
dom.addEventListener(type,fn,false);
}
}else if(document.attachEvent){
return function(dom,type,fn){
dom.attachEvent('on'+type,fn);
}
}else{
return function(dom,type,fn){
dom['on'+type]=fn;
}
}
}();
A.onon=function(dom,type,fn){
if(dom.addEventListener){
A.onon=function(dom,type,fn){
dom.addEventListener(type,fn,false);
}
}else if(dom.attachEvent){
A.onon=function(dom,type,fn){
dom.attachEvent('on'+type,fn);
}
}else{
A.onon=function(dom,type,fn){
dom['on'+type]=fn;
}
}
A.onon(dom,type,fn);
};
var createXHR=(function(){
if(typeof XMLHttpRequest!='undefined'){
return function(){
return new XMLHttpRequest();
};
}else if(typeof ActiveXObject!='undefined'){
return function(){
return new ActiveXObject();
}
}else{
return function(){
throw new Error("No XHR object available.");
};
}
})();
function createXHRR(){
if(typeof XMLHttpRequest!='undefined'){
createXHRR=function(){
return new XMLHttpRequest();
};
}else if(typeof ActiveXObject!='undefined'){
createXHRR=function(){
return new ActiveXObject();
};
}else{
createXHRR=function(){
throw new Error('XHR对象建立不成功。');
};
}
return createXHRR();
}
var xhr=new createXHR();
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if((xhr.status>=200&&xhr.status<300)||xhr.status==304){
console.log(xhr.responseText);
}else{
console.log('获取数据不成功:'+xhr.status);
}
}
};
xhr.open('get','example.txt',true);
xhr.send();
var xhr2=new createXHR();
xhr2.onreadystatechange=function(){
if(xhr2.readyState==4){
if((xhr2.status>=200&&xhr.status<300)||xhr2.status==304){
console.log(xhr2.responseText);
}else{
console.log('获取数据不成功:'+xhr2.status);
}
}
};
xhr2.open('get','example.txt',true);
xhr2.send();
var btn=document.getElementById('reg');
A.onon(btn,'click',function(){
alert('11');
});
</script>
</body>
</html>
|