似乎Zepto.js (1.0rc1)版本没有引入这个api。
参见tag v1.0rc1中的line 152和line 100-108
dom = zepto.fragment(selector.trim(), RegExp.$1), selector = null
zepto.fragment = function(html, name) {
if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
if (!(name in containers)) name = '*'
var container = containers[name]
container.innerHTML = '' + html
return $.each(slice.call(container.childNodes), function(){
container.removeChild(this)
})
}
和167行和110-128行在master
dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null
zepto.fragment = function(html, name, properties) {
if (html.replace) html = html.replace(tagExpanderRE, "<$1></$2>")
if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
if (!(name in containers)) name = '*'
var nodes, dom, container = containers[name]
container.innerHTML = '' + html
dom = $.each(slice.call(container.childNodes), function(){
container.removeChild(this)
})
if (isPlainObject(properties)) {
nodes = $(dom)
$.each(properties, function(key, value) {
if (methodAttributes.indexOf(key) > -1) nodes[key](value)
else nodes.attr(key, value)
})
}
return dom
}
另请阅读issue。也许它会在 1.0 大的时候引入。
现在,在 api 可以工作之前,您可以使用以下代码执行此操作:
element = $("<ul />").attr({id:"myID"});