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

在每个匹配的元素之前插入内容。

返回值:jQuery

参数:

  • content (<Content>): 插入到每个目标前的内容
 
示例:

在所有段落之前插入一些HTML标记代码。

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

HTML 代码:

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

结果:

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

在所有段落之前插入一个元素。

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

HTML 代码:

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

结果:

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

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

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

HTML 代码:

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

结果:

<b>Hello</b><p>I would like to say:   </p>
 
before( content )

Insert content before each of the matched elements.

Return value: jQuery
Parameters:

  • content (<Content>): Content to insert before each target.
 

Example:

Inserts some HTML before all paragraphs.

 $("p").before("<b>Hello</b>");  
Before:
 <p>I would like to say: </p>  
Result:
 <b>Hello</b><p>I would like to say: </p>

Example:

Inserts an Element before all paragraphs.

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

Before:

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

Result:

 <b id="foo">Hello</b><p>I would

Example:

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

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

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