'*')
},
//当有参数时,设置集合每条记录的HTML,没有参数时,则为获取集合第一条记录的HTML,如果集合的长度为0,则返回null
html: function(html) {
return html === undefined ?
//参数html不存在时,获取集合中第一条记录的html
(this.length > 0 ? this[0].innerHTML : null) :
//否则遍历集合,设置每条记录的html
this.each(function(idx) {
//记录原始的innerHTMl
var originHtml = this.innerHTML
//如果参数html是字符串直接插入到记录中,
//如果是函数,则将当前记录作为上下文,调用该函数,且传入该记录的索引和原始innerHTML作为参数
$(this).empty().append(funcArg(this, html, idx, originHtml))
})
},
text: function(text) {
//如果不给定text参数,则为获取功能,集合长度大于0时,取第一条数据的textContent,否则返回null,
//如果给定text参数,则为集合的每一条数据设置textContent为text
return text === undefined ? (this.length > 0 ? this[0].textContent : null) : this.each(function() {
this.textContent = text
})
},
attr: function(name, value) {
var result
//当只有name且为字符串时,表示获取第一条记录的属性
return (typeof name == 'string' && value === undefined) ?
//集合没有记录或者集合的元素不是node类型,返回undefined
(this.length == 0
关键词:zepto是啥