使用 YUI 创建 HTML 元素 [英] Create HTML element with YUI

查看:27
本文介绍了使用 YUI 创建 HTML 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码通过 YUI 在页面正文中创建一个 html 元素.此代码不会产生任何错误.

I am using following code to create a html element in the page body with using YUI. This code doesn't produce any error.

问题是,没有在 html 页面中创建段落元素.

The issue is, the paragraph element is not created in the html page.

<html>
    <head>
        <title>YUI Test</title>
        <meta charset="UTF-8">
        <script src="http://yui.yahooapis.com/3.14.1/build/yui/yui-min.js"></script>
        <script>
            // Create a YUI sandbox on your page.
            YUI().use('node', function(Y) {
                // Create DOM nodes.
                var contentNode = Y.Node.create('<p>');

                contentNode.setHTML('This is a para created by YUI...');
            });           
        </script>
    </head>
    <body>
        <h1>Page body section...</h1>

    </body>
</html>

推荐答案

节点已创建,但它也与 DOM 分离.您必须使用其中之一将其附加到 DOM

The node is created, but it is also detached from the DOM. You have to attach it to the DOM by using either

Y.one('body').append(contentNode);

contentNode.appendTo(Y.one('body'));

Y.one('nav.main-navigation').insert(contentNode, 'before');

或任何其他在 YUI 中操作 dom 的方法.

or any of the other methods for manipulating dom in YUI.

这篇关于使用 YUI 创建 HTML 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆