$(selector).wrapInner(wrappingElement,function(index))
参数 | 说明 |
wrappingElement | 这是强制性参数。它指定了将哪些HTML元素包装在每个选定元素的内容周围。其可能的值为: HTML元素 jQuery对象 DOM元素 |
function(index) | 这是一个可选参数。它指定一个返回包装元素的函数。 index:它提供元素在集合中的索引位置。 |
<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").wrapInner("<em></em>");
});
});
</script>
</head>
<body>
<p>Hello Guys!</p>
<p>This is bianchenghao6.com</p>
<button>Wrap a emphasized element around the content of each p element</button>
</body>
</html>
Hello Guys!
This is bianchenghao6.com
<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").wrapInner("<em><b><marquee></marquee></b></em>");
});
});
</script>
</head>
<body>
<p>Hello Guys!</p>
<p>This is bianchenghao6.com</p>
<button>Wrap a emphasized element around the content of each p element</button>
</body>
</html>
Hello Guys!
This is bianchenghao6.com
<em> ... </em>标签
<b> ... </b>标签
<marquee> ... </marquee>标记
<!DOCTYPE html>
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("div").click(function () {
var content = "<marquee><b></b></marquee>";
$(this).wrapInner( content );
});
});
</script>
<style>
.div{ margin:12px;padding:12px; border:2px solid #666; width:100px;}
</style>
</head>
<body>
<p>Click on any square below to see the result:</p>
<div class="div" id="destination">bianchenghao6.com</div>
<div class="div" style="background-color:lightpink;">JAVA</div>
<div class="div" style="background-color:green;">SQL</div>
<div class="div" style="background-color:lightyellow;">HTML</div>
</body>
</html>
Click on any square below to see the result: