jquery 控制 wrapInner( html )

wrapInner( html )

将‘html’内容封装在匹配元素集合中每一个元素的内容或是文本上。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("p").wrapInner("<b></b>");
  });
  </script>
  <style>p { background:#bbf; }</style>
</head>
<body>
  <p>Hello</p>
  <p>cruel</p>
  <p>World</p>
</body>
</html>

 

$("p").wrapInner("<b></b>");
将‘<b></b>’封装在匹配p元素中每一个p元素内容上

 

 

wrapInner( elem )

将特殊的‘elem’元素封装在匹配元素集合每一个元素中的内容上

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("p").wrapInner(document.createElement("b"));
  });
  </script>
  <style>p { background:#9f9; }</style>
</head>
<body>
  <p>Hello</p>
  <p>cruel</p>
  <p>World</p>
</body>
</html>

 

$("p").wrapInner(document.createElement("b"));
将特殊元素b匹配在匹配p元素集合每一个p元素的内容上

你可能感兴趣的:(html,jquery)