' 此方法为Form1的加载事件 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' 加载本地文档test.html WebBrowser1.Url = New Uri(String.Format("file:///{0}/test.html", Application.StartupPath)) ' 文档没有加载完毕之前将按钮禁用 Button1.Enabled = False End Sub
' 此方法为Button1的Click事件 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim doc As HtmlDocument = WebBrowser1.Document ' 查找ID为txtCSRQ的元素 Dim element As HtmlElement = doc.GetElementById("txtCSRQ") ' 如果找到了改元素 If element IsNot Nothing Then ' 显示该元素的值 MessageBox.Show(element.GetAttribute("value")) End If End Sub
' 此方法为WebBrowser的DocomentCompleted事件 Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted ' 文档test.html加载完毕后,使按钮可用 Button1.Enabled = True End Sub
回答2:
For Each a In WebBrowser1.Document.getElementsByTagName("input") Select Case a.Name Case "txtCSRQ" Text1.Text = a.Value End Select Next 在VB6.0下用此方法可以得到value的值 1993-05-10,VB.net的话没用过,转换一下应该可以的。