after()方法在所選元素之后插入指定的內(nèi)容。
要在選定元素之前插入內(nèi)容,請使用before()方法。
插入內(nèi)容:
$(selector).after(content)
使用函數(shù)插入內(nèi)容:
$(selector).after(function(index))
在每個段落之后插入內(nèi)容:
$("button").click(function(){
$("p").after("<p>Hello world</p>");
});測試看看?/?使用函數(shù)插入內(nèi)容:
$("button").click(function(){
$("p").after(function(i){
return "<p>這個p元素的索引: " + i + ".</p>";
});
});測試看看?/?| 參數(shù) | 描述 |
|---|---|
| content | 指定要在每個選定元素之后插入的內(nèi)容(可以包含HTML標簽) 可能的值:
|
| function(index) | 指定一個函數(shù),該函數(shù)返回要插入的內(nèi)容
|