随笔分类 -  javascript code

一些常用的代码
JS json object 与 string 相互转换
摘要:object转stirngfunctionobj2str(o){varr=[];if(typeofo=="string"||o==null){returno;}if(typeofo=="object"){if(!o.sort){r[0]="{"for(variino){r[r.length]=i;r[r.length]=":";r[r.length]=obj2str(o[i]);r[r.length]=",";}r[r.length-1]="}"}else{r[0]=&quo 阅读全文

posted @ 2011-10-23 00:20 wuye1200 阅读(253) 评论(0) 推荐(0)

数组去重记录下
摘要:Array.prototype.distinct=function(){varret=[];for(i=0,ii=this.length;i<1*ii;i++){for(j=i+1;j<1*this.length;){if(this[i]===this[j]){ret.push(this.splice(j,1)[0]);}else{j++;}}}this.ret=ret;returnthis;}//测试alert(['a','b','c','c','d','b','a', 阅读全文

posted @ 2011-06-14 12:30 wuye1200 阅读(181) 评论(0) 推荐(0)

封装常用代码
摘要:getElementsByClassName附上一片关于getElementsByClassName的文章一篇 http://hszy00232.blog.163.com/blog/static/43022753201042051443548/functiongetElementsByClassName(oElem,strTagName,strClassName){vararrElements=(strTagName=='*'&&oElem.all)?oElem.all:oElem.getElementsByTagName(strTagName);varretu 阅读全文

posted @ 2011-06-02 11:59 wuye1200 阅读(281) 评论(0) 推荐(0)

导航