TUTORIALFrontendFETCHED
jQuery before() 方法
jQuery before() 方法 jQuery HTML/CSS 方法 实例 在每个 <p> 元素前插入内容: [mycode3 type='js'] $('button').click(function(){ $('p').before('Hello world!'); }); [/mycode3] 尝试一下..
Updated 7/16/2026
Tutorial detail pages default to noindex.
jQuery before() 方法
定义和用法
before() 方法在被选元素之前插入指定的内容。
提示:如需在被选元素后插入内容,请使用 after() 方法。
语法
$(selector).before(content,function(index))
| 参数 | 描述 |
|---|---|
| content | 规定要插入的内容(可包含 HTML 标签)。
可能的值:
|
| function(index) | 可选。规定返回待插入内容的函数。
|
更多实例
before() - 通过 HTML、jQuery 和 DOM 创建内容
通过 before() 方法插入内容。
使用函数插入内容
如何使用函数在被选元素前插入内容。
jQuery HTML/CSS 方法