在 YUI 3 中创建文档片段

发布于 2024-10-07 13:29:58 字数 74 浏览 0 评论 0原文

我一直在搜索 YUI3 的文档,但我似乎无法弄清楚如何创建文档片段。我应该只使用文档对象本身吗?我想将它视为 YUI Node 对象。

I've been searching the docs for YUI3, but I cannot seem to figure out how to create a document fragment. Should I just use the document object itself? I would like to treat it as a YUI Node object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

兲鉂ぱ嘚淚 2024-10-14 13:29:58

如果您想创建一个新的空 docfrag,这应该可以:

var frag = Y.all([]).toFrag();

frag 是一个包装 docfrag 的 Node 实例。

If you want to create a new empty docfrag, this should work:

var frag = Y.all([]).toFrag();

frag is then a Node instance wrapping the docfrag.

心碎无痕… 2024-10-14 13:29:58

我认为这相当于卢克的答案(我只是觉得它更具可读性)

var frag = Y.one(document.createDocumentFragment());

I think this is equivalent to Luke's answer (I just find it a little more readable)

var frag = Y.one(document.createDocumentFragment());
别忘他 2024-10-14 13:29:58

我很确定您正在寻找这个 NodeList.toFrag()方法toFrag 源代码在这里底层_nl2frag(NodeList到Frag)代码在这里

我自己没有使用过它,也没有找到示例,但它看起来非常简单。我假设您只是将其追加到另一个节点中。

I'm pretty sure you're looking for this the NodeList.toFrag() method. The toFrag source code is here and the underlying _nl2frag (NodeList to Frag) code is here.

I haven't used it myself and didn't find examples, but it looks pretty straight forward. I assume you would just appendChild it into another node.

乖不如嘢 2024-10-14 13:29:58
var docFrag = Y.Node.create('<div id="foo"><p>Bar</p></div>');

也会起作用。 Y.Node.create 几乎可以做任何事情。最近在非常新的 chrome 版本中遇到了这个问题,很容易解决,但是:

http://yuilibrary。 com/projects/yui3/ticket/2529368

var docFrag = Y.Node.create('<div id="foo"><p>Bar</p></div>');

Would work as well. Y.Node.create can do just about anything. Recently ran into this issue with very new chrome versions, easy work around, however:

http://yuilibrary.com/projects/yui3/ticket/2529368

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文