jQuery 文檔操作 - before() 方法
實(shí)例
在每個(gè) p 元素前插入內(nèi)容:
$("button").click(function(){
$("p").before("<p>Hello world!</p>");
});
定義和用法
before() 方法在被選元素前插入指定的內(nèi)容。
語法
$(selector).before(content)
| 參數(shù) | 描述 |
|---|---|
| content | 必需。規(guī)定要插入的內(nèi)容(可包含 HTML 標(biāo)簽)。 |
使用函數(shù)來插入內(nèi)容
使用函數(shù)在指定的元素前面插入內(nèi)容。
語法
$(selector).before(function(index))
| 參數(shù) | 描述 |
|---|---|
| function(index) |
必需。規(guī)定返回待插入內(nèi)容的函數(shù)。
|