createelement_createElement(W3C DOM核心方法)

createelement

Returns 退货
ElementElement
Throws 投掷
INVALID_CHARACTER_ERRINVALID_CHARACTER_ERR

(Example)

var element = document.createElement('h1');

element.appendChild(document.createTextNode
    ('The man who mistook his wife for a hat'));

The example above creates an <h1> element, and then adds text to it.

上面的示例创建一个<h1>元素,然后向其中添加文本。

The end result of that operation would be this HTML:

该操作的最终结果将是以下HTML:

<h1>The man who mistook his wife for a hat</h1>

争论 (Arguments)

tagname ( 标记名 ( DOMStringDOMString
required
需要

The tagName of the element. In XML this is case-sensitive; in HTML the name can be specified in any case, but will be converted to the canonical upper-case form of HTML tag names.

元素的tagName 。 在XML中,这是区分大小写的。 在HTML中,可以在任何情况下指定名称,但会将其转换为HTML标记名称的规范大写形式。

描述 (Description)

Create an Element node of the specified type.

创建指定类型的Element节点。

The created element can then be added to the document using Node methods such as appendChild or insertBefore.

然后可以使用Node方法(例如appendChildinsertBefore将创建的元素添加到文档中。

A created element implements the Element interface as soon as it’s created, so attributes can be added to it immediately, without having to append it to the document first. If the element has default attributes in this document type, those attributes are automatically created and attached to the element.

创建的元素会在创建后立即实现Element接口,因此可以立即向其添加属性,而不必先将其附加到文档中。 如果元素在此文档类型中具有默认属性,则将自动创建这些属性并将其附加到元素。

This method creates non-namespaced elements; to create a namespaced element, use the DOM 2 “createElementNS”createElementNS method instead.

此方法创建未命名的元素; 要创建命名空间元素,请改用DOM 2“ createElementNS” createElementNS方法。

返回值 (Return value)

The created element node, with its nodeName set to the specified tag name, and its localName, prefix and namespaceURI set to null

创建的元素节点,其nodeName设置为指定的标记名称,其localNameprefixnamespaceURI设置为null

翻译自: https://www.sitepoint.com/createelement-w3c-dom-core-method/

createelement

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值