我如何在 java 中分隔特定标签
How can i separate a specific tag in java
我有这个html:
<p dir="ltr">Hello<br>
<img src="/path"> <br>
<b>hey</b> <b>hello</b> fox<br>
cat</p>
如何将 img
标签与 p
分开?
我希望它是这样的:
<p dir="ltr">Hello<br>
<br>
<b>hey</b> <b>hello</b> fox<br>cat</p>
<img src="/path">
你可以使用indexOf('
然后使用indexOf('>'),得到结束标签的索引
假设你有像
这样的字符串
String html = "<p dir="ltr">Hello<br><img src="path"> <br><b>hey</b> <b>hello</b> fox<br>cat</p>";
String image = html.substring(html.indexOf("<img"), html.indexOf(">"));
那你就知道怎么做了!!
如有其他需要请联系我
var img = document.getElementsByTagName("img");
var div = document.getElementById("div");
div.append(img[0]);
img.remove;
<!DOCTYPE html>
<html>
<body>
<div id="div">
<p dir="ltr">Hello<br>
<img src="" alt="path"></img>
<b>hey</b> <b>hello</b> fox<br>
cat
</p>
</div>
</body>
</html>
我有这个html:
<p dir="ltr">Hello<br>
<img src="/path"> <br>
<b>hey</b> <b>hello</b> fox<br>
cat</p>
如何将 img
标签与 p
分开?
我希望它是这样的:
<p dir="ltr">Hello<br>
<br>
<b>hey</b> <b>hello</b> fox<br>cat</p>
<img src="/path">
你可以使用indexOf('
然后使用indexOf('>'),得到结束标签的索引
假设你有像
这样的字符串String html = "<p dir="ltr">Hello<br><img src="path"> <br><b>hey</b> <b>hello</b> fox<br>cat</p>";
String image = html.substring(html.indexOf("<img"), html.indexOf(">"));
那你就知道怎么做了!!
如有其他需要请联系我
var img = document.getElementsByTagName("img");
var div = document.getElementById("div");
div.append(img[0]);
img.remove;
<!DOCTYPE html>
<html>
<body>
<div id="div">
<p dir="ltr">Hello<br>
<img src="" alt="path"></img>
<b>hey</b> <b>hello</b> fox<br>
cat
</p>
</div>
</body>
</html>