$("#a").append("str") ; 不字符串写入 #a 内部的后面
而 $("#a").after("<div>xxx</div>") ; 是吧 <div>xxx</div> 插入在 #a 外部的后面
而 $("p").appendTo("div") ; 是 p 插入在 div 的后面, 和 append 刚好是相反的。
比如
<div id="one"><p>one</p></div>
jquery
$("#one").append('<div id="two"><p>two</p></div>'); $("<div id='three'><p>three</p></div>").appendTo("#two"); $("#three").after("<div id='four'><p>four</p></div>");
结果
<div id="one"> <p>one</p> <div id="two"> <p>two</p> <div id="three"> <p>three</p> </div> <div id="four"> <p>four</p> </div> </div> </div>
第一步骤 append 表示再 #one 内部的最后 增加 #two
第二步骤 把 #three 插入在 two 内部 的后面
第三步骤 再 three 的外部后面写入 #four
<a href="http://www.ipbbs.net/viewforum.php?id=4"> jquery教程</a>
离线