Skip to content

.append()

.append( content [, content ] )

插入到元素内部的末尾(最后一个子元素)。

.append( content [, content ] ) from @1.0

  • content
    • 类型: htmlString|Element|Text|Array|domtify
    • 描述: DOM 元素、文本节点、元素和文本节点数组、HTML 字符串或 jQuery 对象,插入到匹配元素集的每个元素的末尾。
  • content
    • 类型: htmlString|Element|Text|Array|domtify
    • 描述: 一个或多个DOM 元素、文本节点、元素和文本节点数组、HTML 字符串或 jQuery 对象,插入到匹配元素集的每个元素的末尾。

.append( function ) from @1.0

  • function
    • 类型: Function( Integer index, String html ) => htmlString|Element|Text|domtify
    • 描述: 返回 HTML 字符串、DOM 元素、文本节点或 domtify 对象,用于插入到匹配元素集合中每个元素的末尾。接收元素在集合中的索引位置和元素的旧 HTML 值作为参数。在函数内部,this引用集合中的当前元素。

.append()方法将指定的内容插入为 domtify 集合中每个元素的最后一个子元素。

想象以下html片段:

html
<h2>Greetings</h2>
<div class="container">
  <div class="inner">Hello</div>
  <div class="inner">Goodbye</div>
</div>

您可以创建内容并将其一次插入到多个元素中:

js
d(".inner").append("<p>Test</p>")

每个内部<div>元素都会获得以下新内容:

html
<h2>Greetings</h2>
<div class="container">
  <div class="inner">
    Hello
    <p>Test</p>
  </div>
  <div class="inner">
    Goodbye
    <p>Test</p>
  </div>
</div>

基于 MIT 许可发布