webBrowser集合属性

本文关键字:属性 集合 webBrowser | 更新日期: 2023-09-27 18:22:37

以下是的问题

<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。

webBrowser集合属性

对于"set1_row1"将为:

foreach (HtmlElement he in webBrowser1.Document.All.GetElementsByName("counter"))
{
    if(he.Parent.Parent.getAttribute("id") == "set1_row1")
    {
        he.SetAttribute("value", "HI");
    }
}

你明白了这个想法,所以你可以根据这个例子找出你的确切逻辑。