您好,欢迎访问一九零五行业门户网

风吟的小型JavaScirpt库 (FY.JS)._javascript技巧

小弟刚学javascript没几天不发出来给各位高手指教看看这个小库哪方面可以做的更好实在是不会进步,于是我发出来求喷来了。这个小玩意我开发的初衷就是给自己使用的不建议大家使用。你要是觉得风吟的代码写得不好请你耐心的照顾一下我这个小菜鸟务必跟我说明白哪里不好应该怎么改。我不是重造轮子我只是想提高自己的水平。希望不吝赐教。
比如此库什么地方还可以更精简的写法节省更多代码
比如此库哪里不兼容或者如何写法更完美。
 fy.js已经在google code 上存放.
 项目地址:http://code.google.com/p/fyjs/ 
 文档地址:http://fyjs.googlecode.com/files/fy.js.1.0.doc.zip  (文档地址,里面含有完整例子.)
 文件地址:http://fyjs.googlecode.com/files/fy.1.0.js  (压缩版1.54kb)
源代码经过格式化的...
复制代码 代码如下:
/*
* fy library 1.0
* copyright(c) 2010 fengyin
* blog: http://fengyin.name/
* date: 2010-3-12 16:10:01
* update: http://code.google.com/p/fyjs/
*/
(function(_w,_d) {
var _fy,$,fy;
_w._fy=_w.$= function(i) {
return new fy(i)
};
fy = function(i) {
this.id = _d.getelementbyid(i)
};
fy.prototype = {
ready: function(f) {
var l = _w.onload;
if (typeof(l) == function) {
_w.onload = function() {
l();
f()
}
} else {
_w.onload = f
}
},
html: function(c) {
var g = this.id,
r = g.innerhtml;
if (c) {
g.innerhtml = ;
g.innerhtml += c;
return this
} else {
return r
}
},
val: function(c) {
var g = this.id,
r = g.value;
if (c) {
g.value = ;
g.value += c;
return this
} else {
return r
}
},
text: function(c) {
var g = this.id,
r = g.innertext,
f = g.textcontent;
if (c) {
r ? g.innertext = : g.textcontent = ;
r ? g.innertext += c: g.textcontent += c;
return this
} else {
return r ? r: f
}
},
show: function(f) {
this.id.style.display = block;
f ? f() : null
},
hide: function(f) {
this.id.style.display = none;
f ? f() : null
},
bind: function(t, f) {
var l = this.id,
e = l.attachevent;
e ? l.attachevent(on + t,f):l.addeventlistener(t,f,false)
},
setcookie: function(s) {
var p = new date();
p.settime(p.gettime() + (s.expires || 24) * 60 * 60 * 1000);
_d.cookie = s.name + = + escape(s.value) + ;expires= + p.togmtstring() + ';path=/'
},
getcookie: function(n) {
var c = _d.cookie.match(new regexp((^| ) + n + =([^;]*)(;|$)));
return c ? unescape(c[2]) : null
},
ajax: function(s) {
var a = _w.activexobject ? new activexobject(microsoft.xmlhttp) : new xmlhttprequest();
with(a) {
open(post, s.url, true);
setrequestheader(content-type, application/x-www-form-urlencoded; charset=utf-8);
send(s.data);
onreadystatechange = function() {
if (readystate == 4 && status == 200) {
s.success(responsetext)
}
}
}
}
}
})(window,document);
其它类似信息

推荐信息