定义:wrap() 方法为被选元素添加父元素;
unwrap() 方法删除被选元素。
public static void main(String[] args) {
//img标签添加fingure父标签,如果父标签非p标签进行替换
String html = "<p><img src=\"https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png\"></p>";
Document doc = Jsoup.parse(html);
Elements imgs = doc.getElementsByTag("img");
for (Element image : imgs) {
if ("p".equals(image.parent().tagName())) {
image.parent().unwrap();
}
image.wrap("<figure class=\"image\">");
}
System.out.println(doc.toString());
}
博客介绍了wrap()和unwrap()方法。wrap()方法用于为被选元素添加父元素,unwrap()方法则是删除被选元素,与信息技术中的前端操作相关。
2048

被折叠的 条评论
为什么被折叠?



