问题就在这里
<input type='text'name='TextBox0001'/>例如,要为上面的输入插入一个值,只需使用以下代码:
foreach (HtmlElement he in webBrowser1.Document.All.GetElementsByName("TextBox0001"))
{
he.SetAttribute("value", "HI");
}这没问题,但是如果html代码像下面这样写的话,我该如何为计数器插入一个值呢?
<table>
<tr id='set1_row1'>
<td> <input type='text'name='counter'></td>
</tr>
<tr id='set1_row2'>
<td> <input type='text'name='counter'></td>
</tr>
</table>
</table>我正在使用c# webBrowser。
发布于 2012-02-03 19:32:12
对于"set1_row1“将是:
foreach (HtmlElement he in webBrowser1.Document.All.GetElementsByName("counter"))
{
if(he.Parent.Parent.getAttribute("id") == "set1_row1")
{
he.SetAttribute("value", "HI");
}
}你已经明白了这一点,所以你可以根据这个例子来弄清楚你的逻辑。
https://stackoverflow.com/questions/9127831
复制相似问题