下面是我的HTML。我的要求是找到input
代码id
值,并在label
**for**
属性中放置相同的ID值。喜欢
<label for="beneficiary.trustName">
<div>
<div class="lbl">
<label>
<span id=Trust Name" class="required">*</span>
Trust Name
</label>
</div>
<div class="input">
<input id="beneficiary.trustName" class="inputlgbeneficiary-name" type="text"
name="beneficiary.trustName" value="" size="30" maxlength="30" onkeypress="return(event);">
</div>
</div>
答案 0 :(得分:1)
这样的事情会发生。虽然错误处理不存在。您可以自己添加该部分。
Document doc = Jsoup.parse(content);
Elements inputContainers = doc.getElementsByClass("input");
for(Element inpContainer : inputContainers) {
Element labelContainer = inpContainer.siblingElements().get(0);
Element label = labelContainer.getElementsByTag("label").get(0);
Element input = inpContainer.getElementsByTag("input").get(0);
label.attr("for", input.id());
}
System.out.println(doc);