$.extend = function(target){ var deep, args = slice.call(arguments, 1) if (typeof target == 'boolean') { deep = target target = args.shift() } args.forEach(function(arg){ extend(target, arg, deep) }) return target }
扩展函数 第一个参数为boolean true 则深扩展,
zepto.qsa = function(element, selector){ var found, maybeID = selector[0] == '#', maybeClass = !maybeID && selector[0] == '.', nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked isSimple = simpleSelectorRE.test(nameOnly) return (element.getElementById && isSimple && maybeID) ? // Safari DocumentFragment doesn't have getElementById ( (found = element.getElementById(nameOnly)) ? [found] : [] ) : (element.nodeType !== 1 && element.nodeType !== 9 && element.nodeType !== 11) ? [] : slice.call( isSimple && !maybeID && element.getElementsByClassName ? // DocumentFragment doesn't have getElementsByClassName/TagName maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class element.getElementsByTagName(selector) : // Or a tag element.querySelectorAll(selector) // Or it's not simple, and we need to query all ) }
getElementByClassName 通过class获取节点
getElementByTagName 通过标签回去
获取单个选择器
$.contains = document.documentElement.contains ? function(parent, node) { return parent !== node && parent.contains(node) } : function(parent, node) { while (node && (node = node.parentNode)) if (node === parent) return true return false }
document.documentElement.contains 检测某个节点下是否包含传入的子节点
$.type = type //检测对象类型
$.isFunction = isFunction //是否为函数
$.isWindow = isWindow //是否为window对象
$.isArray = isArray //是否为数组
$.isEmptyObject //是否为空对象
$.isNumeric //是否为有效数字
$.inArray //array的indexof
$.camelCase //驼峰命名
$.trim //去空
$.map //遍历函数,返回一个返回值的集合数组
$.each //遍历元素执行函数
$.grep //array的filter函数
代码仅供参考,具体功能可以自己扩展。
http://www.cnblogs.com/jiebba/p/6529854.html
http://www.cnblogs.com/jiebba 我的博客,来看吧!
如果有错误,请留言修改下 哦!