0

テキスト ボックスがある HTML 文字列があり、その ID で無効化された属性を削除する必要があります。

String baseHtml = "<div id='stylized' class='myform'>"
+ "<input id='txt_question' disabled='disabled' name='preg' type='text' style='width:150px;'>"
+ "</div>";

Document doc = Jsoup.parse(baseHtml);
Elements elements = doc.getElementById("txt_question").select("input");
elements.remove();
elements = doc.select("input");
System.out.println(doc.outerHtml());

問題は、すべての INPUT タグを消去することです。私が望むのは、無効な属性のみを取得することです。助けてください。

4

1 に答える 1

0

Elements#selectはCSS セレクターをサポートしているため、次のように実行できます。

Elements elementTxtQuestion = doc.select("#txt_question"); // selects element with Id 'txt_question'
elementTxtQuestion.removeAttr("disabled"); // removes attribute 'disabled'

詳細については、こちらを参照してください: Use selector-syntax to find elements

于 2013-09-09T19:36:59.270 に答える