我试图通过单击 c# web 浏览器控件中的按钮来提交表单。
[表格代码]
<form action="sendmessage.aspx" method="post" name="sendmessage">
[C#代码]
private void Form1_Load(object sender, EventArgs e)
{
HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
element.text = "function submitForm()
{
document.getElementsByName('sendmessage')[0].value.submit();
}";
head.AppendChild(scriptEl);
}
private void button2_Click(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("submitForm");
}
任何帮助,将不胜感激 。谢谢