<strong>一、方法</strong> <br><br>wrap :把所有匹配的元素,用其他元素的结构化包裹起来 <br><br>wrapAll : 把所有匹配的元素,用单个元素包裹起来 <br><br>wrapInner : 把匹配元素的子类用html结构包裹起来 <br><br><strong>二、实例</strong> <br><br>(1)wrap <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="13361" class="copybut" id="copybut13361" onclick="doCopy('code13361')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code13361"> <br><!DOCTYPE html> <br><html> <br><head> <br><meta charset="UTF-8"> <br><title>Insert title here</title> <br><script type="text/javascript" src="../jquery-2.0.0/jquery-2.0.0.js"></script> <br><script type="text/javascript"> <br>$(function() { <br>$("div a").wrap("<div id='id'></div>"); <br>}); <br></script> <br></head> <br><body> <br><div> <br><a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <br></div> <br></body> <br></html> <br> </div> <br>firebug显示结果: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="5075" class="copybut" id="copybut5075" onclick="doCopy('code5075')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code5075"> <br><!DOCTYPE html> <br><html> <br><head> <br><meta charset="UTF-8"> <br><title>Insert title here</title> <br><script src="../jquery-2.0.0/jquery-2.0.0.js" type="text/javascript"> <br><script type="text/javascript"> <br></head> <br><body> <br><div> <br><div id="id"> <br><a>liuxingyu</a> <br></div> <br><div id="id"> <br><a>liuxingyu</a> <br></div> <br><div id="id"> <br><a>liuxingyu</a> <br></div> <br><div id="id"> <br><a>liuxingyu</a> <br></div> <br></div> <br></body> <br></html> <br> </div> <br>(2)wrapAll <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="83049" class="copybut" id="copybut83049" onclick="doCopy('code83049')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code83049"> <br><!DOCTYPE html> <br><html> <br><head> <br><meta charset="UTF-8"> <br><title>Insert title here</title> <br><script type="text/javascript" src="../jquery-2.0.0/jquery-2.0.0.js"></script> <br><script type="text/javascript"> <br>$(function() { <br>$("div a").wrapAll("<div id='id'></div>"); <br>}); <br></script> <br></head> <br><body> <br><div> <br><a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <br></div> <br></body> <br></html> <br> </div> <br>firebug显示结果: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="22570" class="copybut" id="copybut22570" onclick="doCopy('code22570')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code22570"> <br><!DOCTYPE html> <br><html> <br><head> <br><meta charset="UTF-8"> <br><title>Insert title here</title> <br><script src="../jquery-2.0.0/jquery-2.0.0.js" type="text/javascript"> <br><script type="text/javascript"> <br>$(function() { <br>$("div a").wrapAll("<div id='id'></div>"); <br>}); <br></script> <br></head> <br><body> <br><div> <br><div id="id"> <br><a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <br></div> <br></div> <br></body> <br></html> <br> </div> <br>(3)wrapInner <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="4007" class="copybut" id="copybut4007" onclick="doCopy('code4007')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code4007"> <br><!DOCTYPE html> <br> <br> <br><meta charset="UTF-8"> <br><title>ここにタイトルを挿入</title> <br><script src="../jquery-2.0.0/jquery-2.0.0.js" type="text/javascript"> <br><script type="text/javascript"> <br>$(function() { <br>$("div").wrapInner("<div id='id'></div>"); <br>}); <br></script> <br></head> <br> <br><div> <br><a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <br> </div> <br></body> <br></html> <br> </div> <br>firebug显示结果: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="86253" class="copybut" id="copybut86253" onclick="doCopy('code86253')"><u>复制代码</u></a></span>代码如下:</div> <div class="codebody" id="code86253"> <br><!DOCTYPE html> <br> <br> <br><meta charset="UTF-8"> <br><title>ここにタイトルを挿入</title> <br><script src="../jquery-2.0.0/jquery-2.0.0.js" type="text/javascript"> <br><script type="text/javascript"> <br>$(function() { <br>$("div").wrapInner("<div id='id'></div>"); <br>}); <br></script> <br></head> <br> <br><div> <br><div id="id"> <br><a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <a>liuxingyu</a> <br> </div> <br> </div> <br></body> <br></html> <br>