实例 jQuery 使用函数指定包裹每个选定元素内容的内容

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").wrapInner(function(){
      return "<b></b>"
    });
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Wrap a b element around the content of each p element</button>
</body>
</html>
                    

输出结果