我试图通过JSoup将html文档加载到WebView。文件有图片:
<img class="aligncenter size-full wp-image-21038" src="http://example.com/1.jpg" alt="test" width="1920" height="1080">
<img class="wp-image-21035 size-full" src="http://example.com/2.jpg" alt="test 2" width="1920" height="1080">
<img class="size-full wp-image-21036" src="http://example.com/1.jpg" alt="test 3" width="1920" height="1080">
<img class="aligncenter size-full wp-image-21037" src="http://example.com/1.jpg" alt="test 4" width="1920" height="1080">
我以这种方式将width="1920" height="1080"
更改为width="100%" height="auto"
:
doc = Jsoup.connect("http://example.com/test").get();
entryContent = doc.select("#content .entry-content");
for( Element element : entryContent.select("img")) {
element.attr("width", "100%");
element.attr("height", "auto");
System.out.println(element);
}
logcat显示应用于所有四个图像的新属性
<img class="aligncenter size-full wp-image-21038" src="http://example.com/1.jpg" alt="test" width="100%" height="auto">
<img class="wp-image-21035 size-full" src="http://example.com/2.jpg" alt="test 2" width="100%" height="auto">
<img class="size-full wp-image-21036" src="http://example.com/1.jpg" alt="test 3" width="100%" height="auto">
<img class="aligncenter size-full wp-image-21037" src="http://example.com/1.jpg" alt="test 4" width="100%" height="auto">
但是WebView忽略了第二和第三张图像的新属性。第一张图片和最后一张图片显示正确。哪里有问题?