jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
before |
before(content)
在每个匹配的元素之前插入内容。 返回值:jQuery 参数:
在所有段落之前插入一些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> Insert content before each of the matched elements. Return value: jQuery
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 |