<分区>
我想摆脱仅存在于某些类元素中的“href”属性。
String html="<div>This is my example:
<a class="class1" href="www.example.com">Hello World</a>. More data:
<a class="class2" href="www.nuisance.com">
Keep this text but remove its reference
</a></div>"
期望的输出:
String newhtml="<div>This is my example:
<a class="class1" href="www.example.com">Hello World</a>. More data:
<a class="class2">
Keep this text but remove its reference
</a></div>
我使用 JSoup 来使用 NewTraversor()
和 trasverse
去除属性,但是,它去除了所有指定的属性,而我只想去除与某些类相关的那些。感谢大家的帮助。
最佳答案
你熟悉jQuery吗? ? 可以像这样使用 jQuery 简单地完成:
jQuery('a.class2').removeAttr('href')
关于java - 删除不同类名中存在的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18195869/