如:我想在第2個(gè)DIV的后面動態(tài)去添加一個(gè)DIV,該如何實(shí)現(xiàn)?<div><div>1</div><div>2</div><div>3</div></div>
1 回答
一只萌萌小番薯
TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊
使用 after 方法可以實(shí)現(xiàn)這種效果。
例如,我想在第2個(gè)DIV的后面動態(tài)去添加一個(gè)DIV,該如何實(shí)現(xiàn)?
html 代碼:
1 2 3 4 5 | <div id="parent"> <div id="one">1</div> <div id="two">2</div> <div id="three">3</div> </div> |
Js 代碼:
1 2 3 4 | $(function(){ $("#two").after("<div>我是新添加的內(nèi)容</div>"); //選擇 ID 為 #two 的 DIV 節(jié)點(diǎn),在其后邊添加一個(gè) DIV 節(jié)點(diǎn) }); |
先掌握這種方法,然后再探究其他更多實(shí)現(xiàn)方式。
- 1 回答
- 0 關(guān)注
- 7474 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
