0

特定のクラス要素にのみ存在する「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>

NewTraversor()andを使用して属性を削除するために JSoup を使用していましたがtrasverse、指定されたすべての属性が削除され、特定のクラスに関連付けられているものだけを削除したいと考えています。ご協力ありがとうございます。

4

3 に答える 3

1

jQueryに精通していますか? 次のようにjQueryを使用して簡単に実行できます。

jQuery('a.class2').removeAttr('href')
于 2013-08-12T20:17:30.963 に答える