如果我写成
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
WebBrowser1.Document.Window.Frames(0).Document.GetElementById("me").SetAttribute("value", "7")
WebBrowser1.Document.Window.Frames(0).Document.GetElementById("me").RaiseEvent("onchange")
WebBrowser1.Document.Window.Frames(0).Document.GetElementById("you").SetAttribute("value", "6“)
WebBrowser1.Document.Window.Frames(0).Document.GetElementById("you").RaiseEvent("onchange")
End Sub
第二个好像被选中了一次然后又被还原了~
但如果写成
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
WebBrowser1.Document.Window.Frames(0).Document.GetElementById("me").SetAttribute("value", "7")
WebBrowser1.Document.Window.Frames(0).Document.GetElementById("me").RaiseEvent("onchange")
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
WebBrowser1.Document.Window.Frames(0).Document.GetElementById("you").SetAttribute("value", "6")
WebBrowser1.Document.Window.Frames(0).Document.GetElementById("you").RaiseEvent("onchange")
End Sub
变成两个按钮来操作,第二个就可以成功被选中,这是怎么回事?
------解决思路----------------------
事件是异步的。
第一个RaiseEvent后需要等一会才能响应、并刷新第二个select。
第一段代码 SetAttribute("value", "6") 在前,刷新 select 在后。
------解决思路----------------------
刷新要把整个select的项目都清空,6都没有了,还怎么保持选中。
即使再填充的项目中又有6,和原先的6没关系啊。
而且你填充完肯定强制选了1。
------解决思路----------------------
执行的太快了
服务器还没响应,你就先执行了
------解决思路----------------------
你不要去调用onchange,自己把select刷新填充后选中啊。