HtmlElementCollection inputs = doc.GetElementsByTagName("input");
HtmlElement usr = inputs.GetElementsByName("username")[0];
usr.setAttribute("value", strUsername);
HtmlElement pwd = inputs.GetElementsByName("password")[0];
pwd.GotFocus += new HtmlElementEventHandler(pwd_GotFocus);
pwd.Focus();
void pwd_GotFocus(object sender, HtmlElementEventArgs e)
{
HtmlElement pwd = (HtmlElement)sender;
pwd.SetAttribute("value", strPassword);
}
这段代码演示了如何使用HtmlElementCollection获取HTML页面上的输入元素,并通过GetElementsByName找到特定名称的元素。针对username和password输入框,设置了值并为password字段添加了GotFocus事件处理程序,当获取焦点时自动填充密码。
1036

被折叠的 条评论
为什么被折叠?



