实际上,为了避免 jquery 的东西,我打算直接在表列表中添加行。
您能否通过将值设置为 htmltable 中的字符串或其他方式(HTMLUNIT)来帮助我动态添加行。
--------------
<table id="list4" class="scroll">
</table>
------------------------
package com.test;
import java.io.IOException;
import java.net.MalformedURLException;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomCharacterData;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableCell;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
public class TestMain {
public static void main(String args[])
throws FailingHttpStatusCodeException, MalformedURLException, IOException {
final String htmlContent = "<html><head><title>foo</title></head><body><table id='table1'><tr id='row1'><td>cell1</td></tr><tr id='row2'><td>cell2</td></tr><tr id='row3'><td>cell3</td></tr><tr id='row4'><td>cell4</td></tr><tr id='row5'><td>cell5</td></tr><tr id='row6'><td>cell6</td></tr></table></body></html>";
WebClient webClient = new WebClient();
final HtmlPage page = loadPage(htmlContent);
final HtmlTable table = page.getHtmlElementById("list4");
// want to add to the new row here
for (final HtmlTableRow row : table.getRows()) {
System.out.println("Found row");
for (final HtmlTableCell cell : row.getCells()) {
System.out.println(" Found cell: " + cell.asText());
}
}
}
}