jQuery API jQuery API 中英文对照版
prepend(content)
prepend(content)

向每个匹配的元素内部前置内容。 这是向所有匹配元素内部的开始处插入内容的最佳方式。

返回值:jQuery

参数:

  • content (<Content>): 要插入到目标元素内部前端的内容
 
示例:

向所有段落中前置一些HTML标记代码。

$("p").prepend("<b>Hello</b>");

HTML 代码:

<p>I would like to say: </p>

结果:

<p><b>Hello</b>I would like to say: </p>

示例:

向所有段落中前置一个元素。

$("p").prepend( $("#foo")[0] );

HTML 代码:

<p>I would like to say: </p><b id="foo">Hello</b>

结果:

<p><b id="foo">Hello</b>I would like to say: </p>

示例:

向所有段落中前置一个jQuery对象(类似于一个DOM元素数组)。

$("p").prepend( $("b") );

HTML 代码:

<p>I would like to say: </p><b>Hello</b>

结果:

<p><b>Hello</b>I would like to say: </p>

 

prepend( content )

Prepend content to the inside of every matched element.

This operation is the best way to insert elements inside, at the beginning, of all matched elements.

Return value: jQuery
Parameters:

  • content (<Content>): Content to prepend to the target.
 

Example:

Prepends some HTML to all paragraphs.

 $("p").prepend("<b>Hello</b>");  

Before:

 <p>I would like to say: </p>  

Result:

 <p><b>Hello</b>I would like to say: </p>  


Example:

Prepends an Element to all paragraphs.

 $("p").prepend( $(".foo")[0] );  
Before:
 <p>I would like to say: </p>
   <p>I would like to say: </p> 
  <b class="foo">Hello</b>
   <b class="foo">Good By</b>  
Result:
 <p><b class="foo">Hello</b>I would like to say: </p>
   <p><b class="foo">Hello</b>I would like to say: </p>

(note the [0], that indicates that we only prepend the first element of $(".foo"))

Example:

Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.

 $("p").prepend( $("b") );  
Before:
 <p>I would like to say: </p><b>Hello</b>  
Result:
 <p><b>Hello</b>I would like to say: </p>  
相关链接
WEB开发网 | PHP教程 | Mysql教程 | Apache教程 | 最新文章 | PHP面试题| 网站地图 | Google地图 | Baidu地图 | 在线WEB论坛

WEB技术QQ交流群:245735*** 站长Q号:245735***
版权所有者:WEB开发网 地址:云南省文山州砚山县盘龙乡 滇ICP备12002707号-10
特别声明:本站内容仅供参考,不作为设计及确切依据!想了解更多,可立即进入Bbs提问