$.js
var $=function(_id)
{
var obj=document.getElementById(_id);
//返回一个 加了新的方法的 dom 对象
var returnNewObject=function(_obj)
{
var _newObject=new Object();
//原始 dom 对象
_newObject.object=_obj;
//设置 或访问 innerHTML
_newObject.html=function()
{
var _parmes_arr=arguments;
if(_parmes_arr.length==1)
{
this.object.innerHTML=_parmes_arr[0];
}
else
{
return this.object.innerHTML;
}
}
//简化 getElementsByTagName
_newObject.tags=function(_tagsName)
{
var tagsObj=this.object.getElementsByTagName(_tagsName);
var _objects_arr=[];
for(_i=0;_i<tagsObj.length;_i++)
{
_objects_arr.push(returnNewObject(tagsObj[_i]));
}
return _objects_arr;
}
return _newObject;
}
return returnNewObject(obj);;
}
$.ajax=function(_url,_fun,_method)
{
var _xmlHttp=null;
try
{
_xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
_xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
_xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
_xmlHttp.onreadystatechange=function()
{
if(_xmlHttp.readyState==4&&_xmlHttp.status==200)
{
_fun(_xmlHttp.responseText);
}
}
if(_method=='get')
{
_xmlHttp.open("GET",_url,_bool);
_xmlHttp.send(null);
}
else
{
_xmlHttp.open("POST",_url,_bool);
_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
_xmlHttp.send(_data);
}
}
//设置cookies
$.setCookie=function(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null)?"":";expires="+exdate.toGMTString());
}
//获取cookies
$.getCookie=function(c_name){
if(document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
//增加 事件 监听
$.getEvent=function()
{
var getE=function(e)
{
var e = (e ? e: event);
return e;
}
return getE(window.event);
}
window.onkeydown=function()
{
alert(window.event.keyCode)
alert($.getEvent().keyCode);
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<div id="hello">
<ul>
<li>
<div>
sadfsafsaf
</div>
</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
</ul>
</div>
</body>
</html>
<script type="text/javascript" src="$.js"></script>
<script type="text/javascript">
alert($("hello").tags("li")[0].tags("div")[0].object.innerHTML)
alert($("hello").tags("li")[0].tags("div")[0].html())
//$.ajax();
</script>