标签:include i++ index name prototype typeof nbsp query prot
扩展jquery方法
1.$.extend() 为jQuery类添加添加类方法,可以理解为添加静态方法
例如:
$.extend({
includePath: ‘‘,
include: function(file) {
var files = typeof file == "string" ? [file]:file;
for (var i = 0; i < files.length; i++) {
var name = files[i].replace(/^\s|\s$/g, "");
var att = name.split(‘.‘);
var ext = att[att.length - 1].toLowerCase();
var isCSS = ext == "css";
var tag = isCSS ? "link" : "script";
var attr = isCSS ? " type=‘text/css‘ rel=‘stylesheet‘ " : " language=‘javascript‘ type=‘text/javascript‘ ";
var link = (isCSS ? "href" : "src") + "=‘" + $.includePath + name + "‘";
if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
}
}
});
使用方法:$.include([‘static/js/test.js‘])
2.$.fn
$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效
为数组添加自定义的方法:
如添加remove方法:
Array.prototype.remove = function() {
var what, a = arguments, L = a.length, ax;
while (L && this.length) {
what = a[--L];
while ((ax = this.indexOf(what)) !== -1) {
this.splice(ax, 1);
}
}
return this;
};
标签:include i++ index name prototype typeof nbsp query prot
原文地址:http://www.cnblogs.com/luoyunshu/p/7676301.html