wrapAll()方法将指定的HTML元素包裹在所有选定的元素周围。
$(selector).wrapAll(wrappingElement)
将DIV元素包裹在所有<p>元素周围:
$("button").click(function(){
$("p").wrapAll("<div></div>");
});
测试看看‹/›本示例使用document.createElement()创建DIV元素,并将其包裹在所有<p>元素周围:
$("button").click(function(){
$("p").wrapAll(document.createElement("div"));
});
测试看看‹/›请注意,在此示例中,段落之间的所有内容都被遗忘了,例如(关于我呢?):
这是第一段。
这是第二段。
这是最后一段。
wrap()方法和wrapAll()方法之间的区别:
$("#btn1").click(function(){
$("p").wrap("<div></div>");
});
$("#btn2").click(function(){
$("p").wrapAll("<div></div>");
});
测试看看‹/›参数 | 描述 |
---|---|
wrappingElement | 指定要包裹所有选定元素的结构 可能的值:
|