<html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").wrap(function(){ return "<div></div>" }); }); }); </script> <style type="text/css"> div{background-color:yellow;padding:10px;} </style> </head> <body> <p>这是一个段落。</p> <button>用 div 元素来包围 p 元素</button> </body> </html>
结果:
编辑上面的代码,点击查看结果。
yige.org
- 试一个