|
Posted on
2009-03-13 13:37
Heclei
阅读( 530)
评论()
编辑
收藏
举报
Cookie:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif) Cookie
1 function getCookie(c_name)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif) {
3 if (document.cookie.length>0)
4![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
5 c_start=document.cookie.indexOf(c_name + "=");
6 if (c_start!=-1)
7![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
8 c_start=c_start + c_name.length+1;
9 c_end=document.cookie.indexOf(";",c_start);
10 if (c_end==-1)
11 c_end=document.cookie.length;
12 return decodeURIComponent(document.cookie.substring(c_start,c_end));
13 }
14 }
15 return null;
16 }
17![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18 function setCookie(c_name,value,expiredays)
19![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif) {
20 var exdate=new Date();
21 exdate.setDate(exdate.getDate()+expiredays);
22 document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate);
23 }
getElementsByClassName:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif) getElementsByClassName
1![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif) function getElementsByClassName(searchClass, domNode, tagName) {
2 alert(searchClass);
3 if (domNode == null) domNode = document;
4 if (tagName == null) tagName = '*';
5 var el = new Array();
6 var tags = domNode.getElementsByTagName(tagName);
7 var tcl = " "+searchClass+" ";
8![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) for(i=0,j=0; i<tags.length; i++) {
9 var test = " " + tags[i].className + " ";
10 if (test.indexOf(tcl) != -1)
11 el[j++] = tags[i];
12 }
13![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14 alert(el);
15 return el;
16 }
Event
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif) Event
1 var EventUtil=new Object;
2 //oTarget:目标;sEventType:事件名称;funName:事件触发的函数名;
3![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif) EventUtil.addEvent=function(oTarget,sEventType,funName) {
4![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if(oTarget.addEventListener) {//for DOM;
5 oTarget.addEventListener(sEventType,funName, false);
6![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) }else if(oTarget.attachEvent) {
7 oTarget.attachEvent("on"+sEventType,funName);
8![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) }else {
9 oTarget["on"+sEventType]=funName;
10 }
11 };
12![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif) EventUtil.removeEvent=function(oTarget,sEventType,funName) {
14![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if(oTarget.removeEventListener) {//for DOM;
15 oTarget.removeEventListener(sEventType,funName, false);
16![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) }else if(oTarget.detachEvent) {
17 oTarget.detachEvent("on"+sEventType,funName);
18![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) }else {
19 oTarget["on"+sEventType]=null;
20 }
21 };
比较实用的,不需要很多无用的代码.
|